sarah-quinones / faer-rs

Linear algebra foundation for the Rust programming language
https://faer-rs.github.io
MIT License
1.82k stars 61 forks source link

Cannot create a `SymbolicSparseRowMat` with `SymbolicSparseRowMat::new_checked()` #142

Closed ThomAub closed 2 months ago

ThomAub commented 2 months ago

Describe the bug

Cannot create a SymbolicSparseRowMat with SymbolicSparseRowMat::new_checked() or new_unsorted_checked()

*To Reproduce**

pip install numpy scipy 
import numpy as np
import scipy.sparse

(nrows, ncols) = (4, 10)

random_matrix = scipy.sparse.random(num_rows, num_cols, density=0.2, format='csr', dtype=np.float64)

# print(f"CSR data array (values): {random_matrix.data}")
print(f"{nrows=} {ncols=}")
print(f"CSR indptr array (row_ptrs): vec!{random_matrix.indptr}")
print(f"CSR indices array  (indices): vec!{random_matrix.indices}")
// src/sparse/csr/symbolic_own.rs
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn symbolic_sparse_row_mat_new_checked() {
        let nrows = 4;
        let ncols = 10;
        let row_ptrs = vec![0_u32, 4, 6, 6, 8];
        let col_indices = vec![0_u32, 1, 3, 5, 0, 3, 4, 5];
        let new_checked =
            SymbolicSparseRowMat::new_checked(nrows, ncols, row_ptrs, None, col_indices);
    }
    assert_eq!(new_checked.nrows, 4);
}
---- sparse::csr::symbolic_own::tests::symbolic_sparse_row_mat_new_checked stdout ----
thread 'sparse::csr::symbolic_own::tests::symbolic_sparse_row_mat_new_checked' panicked at src/sparse/csr/symbolic_own.rs:358:13:
index out of bounds: the len is 5 but the index is 10
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_bounds_check
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:275:5
   3: faer::sparse::csr::symbolic_ref::SymbolicSparseRowMatRef<I>::new_checked
             at ./src/sparse/csr/symbolic_ref.rs:93:17
   4: faer::sparse::csr::symbolic_own::SymbolicSparseRowMat<I>::new_checked
             at ./src/sparse/csr/symbolic_own.rs:52:9
   5: faer::sparse::csr::symbolic_own::tests::symbolic_sparse_row_mat_new_checked
             at ./src/sparse/csr/symbolic_own.rs:358:13
   6: faer::sparse::csr::symbolic_own::tests::symbolic_sparse_row_mat_new_checked::{{closure}}
             at ./src/sparse/csr/symbolic_own.rs:352:45
   7: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

failures:
    sparse::csr::symbolic_own::tests::symbolic_sparse_row_mat_new_checked

test result: FAILED. 30 passed; 1 failed; 0 ignored; 0 measured; 233 filtered out; finished in 1.74s