Bashir Abdelwahed
Bashir Abdelwahed

Reputation: 512

Rust: problem using ndarray-linalg & ndarray crates

I am writing a cross compiled library in Rust (that will work on IOS/Android/Linux/MacOS). I am using ndarray to implement the algorithms.

I need to calculate the norm of an ArrayBase. I found ndarray-linalg which is a crate that implements lots of traits on ndarray's types.

But I am unable to use it:

// Cargo.toml
ndarray = { version = "0.15.1", default-features = true } 
ndarray-linalg = {version = "0.13.1"}

// src/main.rs
use ndarray::*;
use ndarray_linalg::*;

fn main() {
    let foo = ArrayBase::from(&[1,2,3]);
    foo.norm_l2(); // produces error
      //^^^^^^^ method not found in `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
}

So here I have 2 questions:

  1. How to solve this problem and make these methods accessible in my program ?
  2. Is it a good idea to use these crates for compiling against android & IOS architectures anyway?

Thanks in advance.

Upvotes: 2

Views: 849

Answers (1)

Ben
Ben

Reputation: 560

ndarray-linalg version 0.13.1 requires ndarray version 0.14. So you could either reduce your ndarray version to 0.14, in which case your code will work, or remove the ndarray-linalg dependency. If you want to stay on ndarray 0.15.1 and only need to compute an L2 norm, it may be easiest to implement that yourself in a couple of lines.

ndarray version 0.15 was only released a week ago, so there might be an ndarray-linalg release that supports it soon.

ndarray-linalg currently only supports the x86_64 instruction set.

Upvotes: 1

Related Questions