sparsemat / sprs

sparse linear algebra library for rust
Apache License 2.0
386 stars 45 forks source link

Multiplication can break when one dimension is 0 #239

Closed avangogo closed 3 years ago

avangogo commented 3 years ago

I ran across an edge case where the multiplication panicked with ''assertion failed: nb_threads > 0' coming from the following line. https://github.com/vbarrielle/sprs/blob/2fd6cc3e6b3f9261e33c0744b258f4464302039e/src/sparse/smmp.rs#L48

The matrices multiplied are the following zero matrices with one empty dimension CsMatBase { storage: CSR, nrows: 0, ncols: 11, indptr: [0], indices: [], data: [] } CsMatBase { storage: CSR, nrows: 11, ncols: 11, indptr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], indices: [], data: [] } The example does not make really sense, but it should still returns a zero (0,11)-matrix. I guess that it is enough to slightly relax the assert.

vbarrielle commented 3 years ago

You're right, this case should be allowed.

vbarrielle commented 3 years ago

The fix has been pushed in v0.9.2