ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

`linalg` and `stats` are incompatible with ndarray 0.16.0

Open ivan-aksamentov opened this issue 1 year ago • 3 comments

Just linking the issues from the other repos for visibility:

  • https://github.com/rust-ndarray/ndarray-linalg/issues/380
  • https://github.com/rust-ndarray/ndarray-stats/issues/97

This could be due to version mismatch in the dependencies.

Numerous third-party dependencies are also broken.

Things like .inv() (from linalg) and .argmax() from stats are essential for many applications. So, without these packages working it is not possible to take advantage of the improvements of ndarray 0.16, no matter how good they are.

I believe that before releasing new versons of ndarray maintainers should take care that at least the packages in the same organization work correctly.

I'd also consider to move the packages into a single workspace. This way it's easier to spot problems and to maintain them.

ivan-aksamentov avatar Aug 20 '24 01:08 ivan-aksamentov

Hi, do you have an example of them breaking? They should still work if keeping the versions constant, i.e. using ndarray 0.15 until the relevant crates have been updated.

bluss avatar Aug 20 '24 10:08 bluss

Ndarray-stats is owned by the ndarray release team, so I could make releases there. For ndarray-linalg we need to involve the crate owners that can make a release.

bluss avatar Aug 25 '24 17:08 bluss

Hi, do you have an example of them breaking?

Example from ndarray_linalg docs no longer works.

use approx::AbsDiffEq; // for abs_diff_eq
use ndarray::{array, Array1, Array2};
use ndarray_linalg::{LeastSquaresSvd, LeastSquaresSvdInto, LeastSquaresSvdInPlace};

let a: Array2<f64> = array![
    [1., 1., 1.],
    [2., 3., 4.],
    [3., 5., 2.],
    [4., 2., 5.],
    [5., 4., 3.]
];
// solving for a single right-hand side
let b: Array1<f64> = array![-10., 12., 14., 16., 18.];
let expected: Array1<f64> = array![2., 1., 1.];
let result = a.least_squares(&b).unwrap();
assert!(result.solution.abs_diff_eq(&expected, 1e-12));

// solving for two right-hand sides at once
let b_2: Array2<f64> =
    array![[-10., -3.], [12., 14.], [14., 12.], [16., 16.], [18., 16.]];
let expected_2: Array2<f64> = array![[2., 1.], [1., 1.], [1., 2.]];
let result_2 = a.least_squares(&b_2).unwrap();
assert!(result_2.solution.abs_diff_eq(&expected_2, 1e-12));

// using `least_squares_in_place` which overwrites its arguments
let mut a_3 = a.clone();
let mut b_3 = b.clone();
let result_3 = a_3.least_squares_in_place(&mut b_3).unwrap();

// using `least_squares_into` which consumes its arguments
let result_4 = a.least_squares_into(b).unwrap();
// `a` and `b` have been moved, no longer valid

VlaDexa avatar Aug 29 '24 13:08 VlaDexa

@VlaDexa I mean for examples, existing projects that stopped compiling or were broken by ndarray 0.16. That would be interesting. Any example requires a Cargo.toml or dependency information to be reproducible.

bluss avatar Aug 31 '24 08:08 bluss

I don't have a public example, but in a private project that updated to ndarray 0.16, all our linear algebra code broke because the ndarray 0.16 types don't implement the traits in ndarray-linalg. This was an especially confusing error to encounter because ndarray-linalg's version number is already 0.16, implying API compatibility. Of course, nothing is broken if we stay on 0.15.

aristaeus avatar Sep 02 '24 07:09 aristaeus

existing projects that stopped compiling or were broken by ndarray 0.16

My project was broken by ndarray 0.16. When I tried to update to the new version it stopped compiling because of incompatible structs.

Any example requires a Cargo.toml or dependency information to be reproducible.

Three crates from the first three lines of my somewhat minimal example are all the dependencies you need. I don't know how you guys do stuff around here, but I was taught that a minimal example would be better than saying "oh my project doesn't work now"

VlaDexa avatar Sep 02 '24 12:09 VlaDexa

Ok, that's the line.

I've been the person who has been reaching out across the team to try to get this to work, we solved one of the crates. This is a bug in ndarray-linalg and not a problem in this crate. As noted by user stories above, projects continue to work unless updates are attempted (and updates will work when the issue is resolved).

Please refer to the ~~upstream~~ downstream issue https://github.com/rust-ndarray/ndarray-linalg/issues/380

bluss avatar Sep 02 '24 13:09 bluss