sparsemat / sprs

sparse linear algebra library for rust
Apache License 2.0
396 stars 47 forks source link

to_csr() can create matrices with invalid indptr #170

Closed avangogo closed 5 years ago

avangogo commented 5 years ago

It seems that the conversion function from TrimatI to CsMat does not work properly when the matrix has empty lines. The following code

let tri_mat = sprs::TriMatI::new((2,4));
let m: sprs::CsMat<u64> = tri_mat.to_csr();
println!("{:?}", m);
let _ = m.get(1,1); 

outputs

CsMatBase { storage: CSR, nrows: 2, ncols: 4, indptr: [0, 1], indices: [0], data: [0] }

and then logically panics with index out of bounds: the len is 2 but the index is 2 in .../sprs-0.6.5/src/sparse/csmat.rs:1056:20.

vbarrielle commented 5 years ago

Thanks for the report, I should have a fix soon.