Ndarray-conv Cannot import method from trait?

I'm trying to use crates ndarray and ndarray-conv.

From what I understand, crate ndarray-conv, adds traits to structs of crate ndarray to give them convolution methods.

According to the documentation of ndarray-conv, use ndarray_conv::ConvExt; should be enough to import the trait and get method .conv:

use ndarray::{Array, array};
use ndarray_conv::{ConvExt, ConvMode, PaddingMode};

fn main() -> Result<(), anyhow::Error> {
    let data = Array::from_shape_vec((2, 3), vec![1,2,3,4,5,6])?;
    let kernel = array![[1,1,1],[1,0,1],[1,1,1]];
    dbg!(&data);
    dbg!(&kernel);
    let x = data.conv(
        &kernel,
        ConvMode::Same,
        PaddingMode::Zeros,
    );

    dbg!(x);
    
    Ok(())
}

However, this code doesn't compile. Cargo tells me Array doesn't have a method named conv:

error[E0599]: no method named `conv` found for struct `ArrayBase<OwnedRepr<i32>,
 Dim<[usize; 2]>, i32>` in the current scope
  --> src/main.rs:15:18
   |
15 |     let x = data.conv(
   |             -----^^^^ method not found in `ArrayBase<OwnedRepr<i32>, Dim<[u
size; 2]>, i32>`

How can I get method .conv?

What version of ndarray are you using? I assume v0.17. ndarray-conv works with ndarray v0.16. If I'm right and you are using ndarray v0.17, downgrading to v0.16 should solve ConvExt not being implemented for your array.

1 Like

That solved it, thank you!

1 Like

For context, I opened an issue with ndarray-conv as a reminder to upgrade to ndarray v0.17:

1 Like

The upgrade was quickly implemented by the maintainer. You can now use ndarray v0.17 with ndarray-conv v0.6.

1 Like