sparse_npz 0.1.0

Reader and writer for SciPy sparse matrices saved in the NumPy .npz format (CSC and CSR).
Documentation
  • Coverage
  • 55.81%
    24 out of 43 items documented0 out of 17 items with examples
  • Size
  • Source code size: 52.37 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 566.89 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • daniel-x/sparse_npz
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • daniel-x

sparse_npz

Reader and writer for SciPy sparse matrices stored in the NumPy .npz format, implemented directly in Rust.

scipy.sparse.save_npz writes a zip bundle of .npy arrays (format, shape, data, indices, indptr). This crate reads those bundles, in either CSC or CSR form, and writes them back in CSC form, exchanging the matrix as a CscMatrix. The element dtype is preserved end to end: the reader decodes the values into a typed Values (boolean; any signed or unsigned 8/16/32/64-bit integer; or 32/64-bit float) and the writer emits that same dtype.

Members are read whether they are stored, DEFLATE-compressed, or Zstandard-compressed. They are written DEFLATE-compressed by default (as SciPy does, so the output is universally readable). The compression is selectable via write_npz_with:

  • Compression::Deflate { level } - level in 1..=264 (1..=9 via flate2, 10..=264 via Zopfli), None for the default of 6.
  • Compression::Zstd { level } - level in roughly -7..=22, None for the default of 3. Smaller, but only readable by newer readers (numpy/scipy on Python 3.14 or later).

Only little-endian, C-order .npy data is handled, which is what NumPy and SciPy produce on the platforms targeted here.

use sparse_npz::CscMatrix;

let m = CscMatrix::read_npz("matrix.npz")?;
println!("{}x{}, {} nonzeros", m.rows, m.cols, m.nnz());
m.write_npz("copy.npz")?;

License

Licensed under either of Apache License, Version 2.0 (LICENSE-APACHE) or MIT license (LICENSE-MIT) at your option.

Authorship

This project, including its purpose and overall architecture, was conceived and designed by its human authors. The implementation was generated in full with AI assistance (Claude Code), under the human authors' direction.

Note

This crate is an independent implementation of the on-disk formats used by NumPy and SciPy. It is not affiliated with or endorsed by those projects; their names are used only descriptively, to identify the formats it reads and writes.