ConvExt

Trait ConvExt 

Source
pub trait ConvExt<'a, T, S, SK, const N: usize>
where T: NumAssign + Copy, S: RawData, SK: RawData,
{ // Required method fn conv( &self, kernel: impl IntoKernelWithDilation<'a, SK, N>, conv_mode: ConvMode<N>, padding_mode: PaddingMode<N, T>, ) -> Result<Array<T, Dim<[Ix; N]>>, Error<N>>; }
Expand description

Extends ndarray’s ArrayBase with convolution operations.

This trait adds the conv method to ArrayBase, enabling standard convolution operations on N-dimensional arrays.

§Type Parameters

  • T: The numeric type of the array elements.
  • S: The data storage type of the input array.
  • SK: The data storage type of the kernel array.

Required Methods§

Source

fn conv( &self, kernel: impl IntoKernelWithDilation<'a, SK, N>, conv_mode: ConvMode<N>, padding_mode: PaddingMode<N, T>, ) -> Result<Array<T, Dim<[Ix; N]>>, Error<N>>

Performs a standard convolution operation.

This method convolves the input array with a given kernel, using the specified convolution mode and padding.

§Arguments
  • kernel: The convolution kernel. Can be a reference to an array, or an array with dilation settings created using with_dilation().
  • conv_mode: The convolution mode (Full, Same, Valid, Custom, Explicit).
  • padding_mode: The padding mode (Zeros, Const, Reflect, Replicate, Circular, Custom, Explicit).
§Returns

Returns Ok(Array<T, Dim<[Ix; N]>>) containing the convolution result, or an Err(Error<N>) if the operation fails (e.g., due to incompatible shapes or zero-sized dimensions).

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

let input = array![[1, 2, 3], [4, 5, 6]];
let kernel = array![[1, 1], [1, 1]];
let result = input.conv(&kernel, ConvMode::Same, PaddingMode::Zeros).unwrap();

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T, S, SK, const N: usize> ConvExt<'a, T, S, SK, N> for ArrayBase<S, Dim<[Ix; N]>>
where T: NumAssign + Copy, S: Data<Elem = T> + 'a, SK: Data<Elem = T> + 'a, Dim<[Ix; N]>: RemoveAxis, [Ix; N]: IntoDimension<Dim = Dim<[Ix; N]>>, SliceInfo<[SliceInfoElem; N], Dim<[Ix; N]>, Dim<[Ix; N]>>: SliceArg<Dim<[Ix; N]>, OutDim = Dim<[Ix; N]>>,

Source§

fn conv( &self, kernel: impl IntoKernelWithDilation<'a, SK, N>, conv_mode: ConvMode<N>, padding_mode: PaddingMode<N, T>, ) -> Result<Array<T, Dim<[Ix; N]>>, Error<N>>

Implementors§