I/O

namespace io

Enums

enum class FileFormat

Values:

enumerator Unknown
enumerator Axiom
enumerator NumPy
enumerator SafeTensors

Functions

FileFormat detect_format(const std::string &filename)

Detect file format by examining magic bytes.

Parameters:

filename – Path to file

Returns:

Detected file format

std::string format_name(FileFormat format)

Get human-readable name for file format.

Tensor load(const std::string &filename, Device device = Device::CPU)

Load tensor from file, auto-detecting format.

Supports: .axfb (FlatBuffers), .npy (NumPy)

Parameters:
  • filename – Path to input file

  • device – Target device (default: CPU)

Returns:

Loaded tensor

std::map<std::string, Tensor> load_archive(const std::string &filename, Device device = Device::CPU)

Load multiple tensors from archive file.

For NumPy files, returns single tensor with filename as key.

Parameters:
  • filename – Path to input file

  • device – Target device

Returns:

Map of tensor names to loaded tensors

void save(const Tensor &tensor, const std::string &filename)

Save tensor to .axfb file (FlatBuffers format).

Parameters:
  • tensor – The tensor to save

  • filename – Path to output file

void save_archive(const std::map<std::string, Tensor> &tensors, const std::string &filename)

Save multiple tensors to .axfb archive file.

Parameters:
  • tensors – Map of tensor names to tensors

  • filename – Path to output archive

std::string to_string(const Tensor &tensor)

Get a NumPy-style string representation of the tensor.

Parameters:

tensor – The tensor to format.

Returns:

A string with the formatted tensor.

inline void save_tensor(const Tensor &tensor, const std::string &filename)
inline Tensor load_tensor(const std::string &filename, Device device = Device::CPU)
inline void save_tensors(const std::map<std::string, Tensor> &tensors, const std::string &filename)
inline std::map<std::string, Tensor> load_tensors(const std::string &filename, Device device = Device::CPU)
class SerializationError : public std::runtime_error
#include <io.hpp>

Subclassed by axiom::io::FileFormatError

Public Functions

inline explicit SerializationError(const std::string &message)
class FileFormatError : public axiom::io::SerializationError
#include <io.hpp>

Public Functions

inline explicit FileFormatError(const std::string &message)
namespace flatbuffers

Functions

bool is_axfb_file(const std::string &filename)

Check if file is a valid Axiom FlatBuffers file.

Parameters:

filename – Path to file

Returns:

True if file has AXFB magic bytes

Tensor load(const std::string &filename, Device device = Device::CPU)

Load tensor from .axfb file.

Parameters:
  • filename – Path to .axfb file

  • device – Target device

Returns:

Loaded tensor (first tensor in archive)

std::map<std::string, Tensor> load_archive(const std::string &filename, Device device = Device::CPU)

Load all tensors from .axfb archive.

Parameters:
  • filename – Path to .axfb file

  • device – Target device

Returns:

Map of tensor names to loaded tensors

void save(const Tensor &tensor, const std::string &filename)

Save tensor to .axfb file.

Parameters:
  • tensor – The tensor to save

  • filename – Path to output file

void save_archive(const std::map<std::string, Tensor> &tensors, const std::string &filename)

Save multiple tensors to .axfb archive.

Parameters:
  • tensors – Map of tensor names to tensors

  • filename – Path to output file

std::vector<std::string> list_archive(const std::string &filename)

List tensor names in archive without loading data.

Parameters:

filename – Path to archive file

Returns:

Vector of tensor names

Tensor load_from_archive(const std::string &filename, const std::string &tensor_name, Device device = Device::CPU)

Load specific tensor from archive by name.

Parameters:
  • filename – Path to archive file

  • tensor_name – Name of tensor to load

  • device – Target device

Returns:

Loaded tensor

namespace numpy

Functions

bool is_npy_file(const std::string &filename)

Check if file has NumPy magic bytes.

Parameters:

filename – Path to file

Returns:

True if file starts with NumPy magic (\x93NUMPY)

Tensor load(const std::string &filename, Device device = Device::CPU)

Load tensor from NumPy .npy file.

Supports:

  • All standard NumPy dtypes (float, int, uint, bool, complex)

  • Both little-endian and big-endian (with automatic conversion)

  • C-order (row major) and Fortran-order (column major) arrays

  • NPY format versions 1.0, 2.0, and 3.0

Parameters:
  • filename – Path to .npy file

  • device – Target device (default: CPU)

Returns:

Loaded tensor

Variables

constexpr uint8_t NPY_MAGIC[] = {0x93, 'N', 'U', 'M', 'P', 'Y'}
constexpr size_t NPY_MAGIC_SIZE = 6
namespace safetensors

Functions

bool is_safetensors_file(const std::string &filename)
std::map<std::string, Tensor> load(const std::string &filename, Device device = Device::CPU)
std::vector<std::string> list_tensors(const std::string &filename)
Tensor load_tensor(const std::string &filename, const std::string &tensor_name, Device device = Device::CPU)