sparse_npz 0.1.0

Reader and writer for SciPy sparse matrices saved in the NumPy .npz format (CSC and CSR).
Documentation
//! Reads a SciPy sparse `.npz` and prints its shape, nnz, and element dtype.
//! With a second argument, also writes the matrix back out (preserving dtype).
//! Usage: `cargo run --example npz_dtype -- IN.npz [OUT.npz]`

use sparse_npz::{CscMatrix, Values};

fn dtype_name(v: &Values) -> &'static str {
    match v {
        Values::Bool(_) => "bool",
        Values::I8(_) => "i8",
        Values::I16(_) => "i16",
        Values::I32(_) => "i32",
        Values::I64(_) => "i64",
        Values::U8(_) => "u8",
        Values::U16(_) => "u16",
        Values::U32(_) => "u32",
        Values::U64(_) => "u64",
        Values::F32(_) => "f32",
        Values::F64(_) => "f64",
    }
}

fn main() {
    let path = std::env::args().nth(1).expect("usage: dtype IN.npz [OUT.npz]");
    let m = CscMatrix::read_npz(&path).expect("read npz");
    println!("rows={} cols={} nnz={} dtype={}", m.rows, m.cols, m.nnz(), dtype_name(&m.values));
    if let Some(out) = std::env::args().nth(2) {
        m.write_npz(&out).expect("write npz");
    }
}