Skip to content

getting no method named svd found for reference &ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>> #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
emiddleton opened this issue May 19, 2021 · 5 comments

Comments

@emiddleton
Copy link

emiddleton commented May 19, 2021

Not sure if this is the write place to ask such questions but I couldn't find anywhere else more specific. I am trying to implement the (Moore-Penrose) pseudo-inverse of a matrix[1]. My code currently looks like

use ndarray::prelude::*;
use ndarray_linalg::*;
use std::cmp::min;
use thiserror::Error;

#[non_exhaustive]
#[derive(Error, Debug)]
pub enum Error {
    #[error("svd failed")]
    SvdFailed,
}

pub fn pinv(a: &Array2<f64>) -> Result<Array2<f64>, Error> {
    //a.conjugate()
    let (n, m) = a.dim();
    let result: (Option<Array1<f64>>, Array1<f64>, Option<Array1<f64>>) =
        a.svd(true, true).map_err(Error::SvdFailed)?;

I am running into issues getting

error[E0599]: no method named `svd` found for reference `&ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>` in the current scope
  --> numrs/src/linalg.rs:16:43
   |
16 |     let (u, s, vt): (_, Array1<_>, _) = a.svd(true, true).unwrap();
   |                                           ^^^ help: there is an associated function with a similar name: `std`

the dependencies part of my Cargo.toml file is the same versions as the ndarray-linalg crate on github[2]

[dependencies]
num-complex = "0.4.0"
num-traits  = "0.2.14"
rand = "0.8.3"
thiserror = "1.0.24"

[dependencies.ndarray]
version = "0.15.1"
features = ["blas", "approx", "std"]
default-features = false

#ndarray-linalg = { version = "0.13.1", features = ["openblas-static"] }
[dependencies.ndarray-linalg]
github = "https://github.com/rust-ndarray/ndarray-linalg/ndarray-linalg"
version = "0.13.1"
features = ["openblas-static"]

[dependencies.lax]
version = "0.1.0"
github = "https://github.com/rust-ndarray/ndarray-linalg/lax"
default-features = false

Any idea's what is going on here. I downloaded the ndarray-linalg source from github and the test run fine with

$ cargo test --features=openblas svd
  1. https://github.com/numpy/numpy/blob/v1.20.0/numpy/linalg/linalg.py#L1915-L2011
  2. https://github.com/rust-ndarray/ndarray-linalg/blob/master/ndarray-linalg/Cargo.toml
@jturner314
Copy link
Member

jturner314 commented May 20, 2021

The versions of ndarray and ndarray-linalg in the Cargo.toml are incompatible. The latest version of ndarray-linalg (0.13.1) provides functionality for ndarray 0.14. Hopefully we'll get a chance to release a new version of ndarray-linalg for ndarray 0.15 soon (#281). Try swiching to ndarray 0.14 for now. By the way, thanks for writing such a detailed, easy to understand issue. :)

@emiddleton
Copy link
Author

Thanks, Is there any way to run locally with the unreleased version of ndarray-linalg. That was what I was trying to do as I am using some features in ndarray 1.15.

Also is there anything I can do to help get a 0.15 version released? Is there a list pre-0.15 release issues?

@jturner314
Copy link
Member

I'm not sure about the status of the next version of ndarray-linalg. My impression is that it was blocked by #277, but I could be wrong. @termoshtt would know more. Something like this would work temporarily:

[dependencies]
ndarray = "0.15"
ndarray-linalg = { git = "https://github.com/rust-ndarray/ndarray-linalg.git", branch = "use-build-uninit", features = ["openblas"] }

This specifies the branch from #287 and the OpenBLAS backend, but you could choose a different version or backend. See the Cargo docs for more information.

@emiddleton
Copy link
Author

Just as a follow up on this, I was not able to get this working without explicitly downloading the source from github and including it by path. i.e.

[dependencies.ndarray]
version = "=0.15.1"
features = ["blas", "approx", "std"]
default-features = false

[dependencies.ndarray-linalg]
path = "../ndarray-linalg/ndarray-linalg"
features = ["openblas-static"]

[dependencies.lax]
path = "../ndarray-linalg/lax"
default-features = false

@tbetcke
Copy link

tbetcke commented May 27, 2021

Apologies to add to this issue. Is there an approximate timeline for the release of the next version of ndarray-linalg? For a project I have already written a couple of components using ndarray 0.15 and now notice that I should have used ndarray 0.14 for ndarray-linalg compatibility. The question is whether to downgrade 0.15 specific library calls to 0.14 compatible versions in my already written code or to simply wait until the next ndarray-linalg version is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants