Skip to content

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

Open
@emiddleton

Description

@emiddleton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions