8 releases (5 breaking)

new 0.6.0 May 1, 2024
0.5.1 Apr 27, 2024
0.4.0 Apr 26, 2024
0.3.0 Apr 26, 2024
0.1.1 Apr 16, 2024

#255 in Algorithms

Download history 316/week @ 2024-04-15 485/week @ 2024-04-22

801 downloads per month

MIT/Apache

125KB
2.5K SLoC

Compressed Sparse Vector (CSV) Binary Matrix Library.

Crates.io MSRV Crate Downloads Coverage report Pipeline status docs.rs License

🦀 Rust package for binary matrices represented in the Compressed Sparse Vector (CSV) format.

📖 For more info on this library, check out the docs.rs docs.

CSVBinaryMatrix is the main structure and maintains the CSV format which is suitable for sparse matrices.

This crate is based on the paper cited in the References section.

Quick Usage

# fn quick_usage() -> Result<(), Box<dyn std::error::Error>> {
use csvbinmatrix::prelude::CSVBinaryMatrix;

let matrix = match CSVBinaryMatrix::try_from(&vec![
    vec![0, 0, 0],
    vec![0, 0, 1],
    vec![0, 1, 1],
    vec![1, 1, 1],
]) {
    Ok(m) => m,
    Err(e) => panic!("[ERROR] Cannot create the matrix: {e}"),
};

println!("Matrix stats");
println!("------------");
println!(
    "Dimensions: {}x{} ({})",
    matrix.number_of_rows(),
    matrix.number_of_columns(),
    matrix.number_of_cells()
);
println!(
    "Number of ones/zeros: {}/{}",
    matrix.number_of_ones(),
    matrix.number_of_zeros()
);
println!("Density: {:.2}%", matrix.density() * 100.0);
println!("Sparsity: {:.2}%", matrix.sparsity() * 100.0);
println!();

println!("Coordinates of ones");
println!("-------------------");
println!("row\tcolumn");
println!("---\t-------");
for coordinates in matrix.iter_ones_coordinates() {
    println!("{}\t{}", coordinates.row(), coordinates.column());
}
println!();

match matrix.to_file("mymatrix.csvbm") {
    Ok(_) => println!("[INFO] File created"),
    Err(e) => println!("[ERROR] Creating the file fails: {e}"),
}

match CSVBinaryMatrix::from_file("mymatrix.csvbm") {
    Ok(m) => {
        println!("[INFO] Read from file");
        assert_eq!(m, matrix)
    }
    Err(e) => println!("[ERROR] Cannot read the file: {e}"),
}
#
#    std::fs::remove_file("mymatrix.csvbm")?;
#    Ok(())
# }

Tutorials

Recent Changes

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

References

This package is based on this paper, where the authors' method is adapted for binary matrices:

Farzaneh, Aiyoub, Hossein Kheırı, et Mehdi Abbaspour Shahmersı. « AN EFFICIENT STORAGE FORMAT FOR LARGE SPARSE MATRICES ». Communications Faculty of Sciences University of Ankara Series A1 Mathematics and Statistics 58, nᵒ 2 (1 août 2009): 1‑10. https://doi.org/10.1501/Commua1_0000000648.

Dependencies

~0.5–1MB
~22K SLoC