pub trait ConvExt<'a, T, S, SK, const N: usize>{
// 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§
Sourcefn 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>>
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 usingwith_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.