Skip to content

Latest commit

 

History

History
69 lines (48 loc) · 1.39 KB

File metadata and controls

69 lines (48 loc) · 1.39 KB

I/O Module

File format support for loading and saving matrices and vectors.

NumPy .npy Format

Load and save matrices/vectors in NumPy's .npy binary format. Useful for exchanging data with Python.

Loading

// Load a dynamic matrix from .npy file
var matrix = try Zigen.loadNpy(f64, allocator, "data/matrix.npy");
defer matrix.deinit();

// Load a dynamic vector from .npy file
var vector = try Zigen.loadNpyVector(f64, allocator, "data/vector.npy");
defer vector.deinit();

Saving

// Save a dynamic matrix to .npy file
try Zigen.saveNpy(f64, matrix, "output/matrix.npy");

// Save a dynamic vector to .npy file
try Zigen.saveNpyVector(f64, vector, "output/vector.npy");

Supported Types

  • f32 (NumPy float32)
  • f64 (NumPy float64)

MatrixMarket Format

Load and save sparse matrices in the MatrixMarket text format.

Loading

const mm_string = @embedFile("test.mtx");
var sp = try Zigen.loadMatrixMarket(f64, allocator, mm_string);
defer sp.deinit();

Saving

const mm_output = try Zigen.saveMatrixMarket(f64, allocator, sparse_matrix);
defer allocator.free(mm_output);

Format Example

%%MatrixMarket matrix coordinate real general
3 3 5
1 1 2.0
1 2 -1.0
2 1 -1.0
2 2 2.0
2 3 -1.0

Note: MatrixMarket uses 1-based indexing. Zigen handles this conversion automatically.