csvbinmatrix

Crates.iocsvbinmatrix
lib.rscsvbinmatrix
version0.8.0
sourcesrc
created_at2024-04-16 15:41:35.569868
updated_at2024-11-15 01:24:07.526945
descriptionBinary matrix Compressed Sparse Vector
homepage
repositoryhttps://gitlab.com/vepain/csvbinmatrix-rust
max_upload_size
id1210371
size193,403
vepain (vepain)

documentation

https://docs.rs/csvbinmatrix

README

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

Add the following into your Cargo.toml configuration file:

[dependencies]
    csvbinmatrix = "0.8.0"
# fn quick_usage() -> Result<(), Box<dyn std::error::Error>> {
use csvbinmatrix::prelude::CSVBinaryMatrix;

let matrix = match CSVBinaryMatrix::try_from(&[
    [0, 0, 0],
    [0, 0, 1],
    [0, 1, 1],
    [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::try_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").unwrap_or(());
#    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.

Commit count: 135

cargo fmt