#matrix #parser #mtx #mm

matrix-market-rs

A simple library to read matrix market file to standard rust types

4 releases

0.1.3 Jun 6, 2023
0.1.2 Apr 27, 2023
0.1.1 Mar 4, 2023
0.1.0 Mar 4, 2023

#1958 in Parser implementations

Download history 26/week @ 2024-12-10 22/week @ 2024-12-17 20/week @ 2025-01-07 3/week @ 2025-01-14 6/week @ 2025-01-21 2/week @ 2025-02-04 9/week @ 2025-02-11 1/week @ 2025-02-18 27/week @ 2025-02-25 8/week @ 2025-03-04 47/week @ 2025-03-11 45/week @ 2025-03-18 3/week @ 2025-03-25

109 downloads per month
Used in 2 crates

Custom license

11KB
204 lines

matrix-market-rs

A simple reader/parser for Matrix Market (.mtx) files to represent sparse or dense matrix in text format.

How to use it ?

Add this to the dependencies in your Cargo.toml.

matrix-market-rs = "0.1"

And then use it in your program.

use matrix_market_rs::{MtxData, SymInfo, MtxError};
use std::fs::File;
use std::io::Write;

fn main() -> Result<(), MtxError> {
    let mtx_content = r#"
    %%MatrixMarket matrix coordinate integer symmetric
    2 2 2
    1 1 3
    2 2 4
    "#;

    let mut f = File::create("sparse2x2.mtx")?;
    f.write_all(mtx_content.trim().as_bytes());
    let shape = [2,2];
    let indices = vec![[0,0], [1,1]];
    let nonzeros = vec![3,4];
    let sym = SymInfo::Symmetric;

    let sparse:MtxData<i32> = MtxData::from_file("sparse2x2.mtx")?;
    assert_eq!(sparse, MtxData::Sparse(shape, indices, nonzeros, sym));
    Ok(())
}

Dependencies

~150KB