Ndarray-conv Cannot import method from trait?

⚓ Rust    📅 2025-12-04    👤 surdeus    👁️ 2      

surdeus

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?

4 posts - 2 participants

Read full topic

🏷️ Rust_feed