sparsemat / sprs

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

Using sprs 0.11 with sprs-ldl 0.9.0 causes a compilation error #294

Closed lfiolhais closed 2 years ago

lfiolhais commented 2 years ago

When using spsrs 0.11 with sprs-ldl a compilation error occurs with LdlNumeric::new().

Cargo.toml

# snip
[dependencies]
sprs = "0.11.0"
sprs-ldl = "0.9.0"

main.rs

use sprs::CsMat;
use sprs_ldl::LdlNumeric;

fn test_mat1() -> CsMat<f64> {
    let indptr = vec![0, 2, 5, 6, 7, 13, 14, 17, 20, 24, 28];
    let indices = vec![
        0, 8, 1, 4, 9, 2, 3, 1, 4, 6, 7, 8, 9, 5, 4, 6, 9, 4, 7, 8, 0, 4, 7, 8, 1, 4, 6, 9,
    ];
    let data = vec![
        1.7, 0.13, 1., 0.02, 0.01, 1.5, 1.1, 0.02, 2.6, 0.16, 0.09, 0.52, 0.53, 1.2, 0.16, 1.3,
        0.56, 0.09, 1.6, 0.11, 0.13, 0.52, 0.11, 1.4, 0.01, 0.53, 0.56, 3.1,
    ];
    CsMat::new_csc((10, 10), indptr, indices, data)
}

fn test_vec1() -> Vec<f64> {
    vec![
        0.287, 0.22, 0.45, 0.44, 2.486, 0.72, 1.55, 1.424, 1.621, 3.759,
    ]
}

fn expected_res1() -> Vec<f64> {
    vec![
        0.099999999999999992,
        0.19999999999999998,
        0.29999999999999999,
        0.39999999999999997,
        0.5,
        0.59999999999999998,
        0.70000000000000007,
        0.79999999999999993,
        0.90000000000000002,
        0.99999999999999989,
    ]
}

fn main() {
    let mat = test_mat1();
    let b = test_vec1();
    let ldlt = LdlNumeric::new(mat.view()).unwrap();
    let x = ldlt.solve(&b);
    let x0 = expected_res1();
    assert_eq!(x, x0);
}

error

error[E0308]: mismatched types
  --> src/main.rs:40:32
   |
40 |     let ldlt = LdlNumeric::new(mat.view()).unwrap();
   |                                ^^^^^^^^^^ expected struct `sprs::sparse::CsMatBase`, found struct `CsMatBase`
   |
   = note: expected struct `sprs::sparse::CsMatBase<_, _, &[_], &[_], &[_]>`
              found struct `CsMatBase<f64, usize, &[usize], &[usize], &[f64]>`
   = note: perhaps two different versions of crate `sprs` are being used?

Can sprs-ldl be updated to support sprs 0.11? Or reexport the sprs used in sprs-ldl?

michael-p commented 2 years ago

Might be same issue as #293

mulimoen commented 2 years ago

A new version of sprs-ldl has been released