ArrayFire: convolve (Non-separable) (original) (raw)
Convolution Integral for any(one through three) dimensional data. More...
| Functions | |
|---|---|
| AFAPI array | convolve (const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT, const convDomain domain=AF_CONV_AUTO) |
| C++ Interface for convolution any(one through three) dimensional signals. More... | |
| AFAPI array | fftConvolve (const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT) |
| C++ Interface for FFT-based convolution any(one through three) dimensional signals. More... | |
Convolution Integral for any(one through three) dimensional data.
A convolution is a common operation between a source array, a, and a filter (or kernel) array b. The answer to the convolution is the same as computing the coefficients in polynomial multiplication, if a and b are the coefficients.
Another way to think about it is that the filter kernel is centered on each pixel in a, and the output for that pixel or data point is the sum of the products.
Depending on the size of the signal and the filter, any one of the following batch mode convolutions take place.
- No Batch - Single filter applied to single input.
- Filter is Batched - Many filters applied on same input
- Signal is Batched - Single filter applied to a set of inputs.
- Identical Batches - A set of filters applied onto to a set of inputs in one-to-one correspondence.
- Non overlapping Batches - All batched filters are applied to all batched signals. The batch axis of Signal and Filter should not be the same.
Note
All non-overlapping(interleaved) convolutions default to frequency domain AF_CONV_FREQ irrespective of the provided convolution mode argument.
This version of convolution function delegates the call to respective 1D, 2D or 3D convolution functions internally.
Convolution dimensionality is \( \min (sd, fd) \) where sd & fd are dimensionality of signal and filter respectively. This formulation only decides the dimensionality of convolution.
Given below are some examples on how convolution dimensionality is computed.
| Signal Size | Filter Size | Input Rank | Filter Rank | Convolve Dimensionality |
|---|---|---|---|---|
| \( [m \ n \ 1 \ 1] \) | \( [m \ 1 \ 1 \ 1] \) | 2 | 1 | \( min(2, 1) => \) 1D |
| \( [m \ 1 \ 1 \ 1] \) | \( [m \ n \ 1 \ 1] \) | 1 | 2 | \( min(1, 2) => \) 1D |
| \( [m \ n \ 1 \ 1] \) | \( [m \ n \ 1 \ 1] \) | 2 | 2 | \( min(2, 2) => \) 2D |
| \( [m \ n \ 1 \ 1] \) | \( [m \ n \ p \ 1] \) | 2 | 3 | \( min(2, 3) => \) 2D |
| \( [m \ n \ 1 \ p] \) | \( [m \ n \ 1 \ q] \) | 4 | 4 | 3D |
| \( [m \ n \ p \ 1] \) | \( [m \ n \ q \ 1] \) | 3 | 3 | \( min(3, 3) => \) 3D |
Note
In the cases similar to the fifth row of the above table, signal and filter are of rank 4, the function delegates the operation to three dimensional convolution convolve3
If the operation you intend to perform doesn't align with what this function does, please check the rank specific convolve functions (hyperlinked below) documentation to find out more.
C++ Interface for convolution any(one through three) dimensional signals.
Example for convolution on one dimensional signal in one to one batch mode
A multi dimensional data container.
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.
AFAPI array convolve(const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT, const convDomain domain=AF_CONV_AUTO)
C++ Interface for convolution any(one through three) dimensional signals.
Example for convolution on two dimensional signal in one to one batch mode
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
C++ Interface to generate an array with elements set to a specified value.
Example for convolution on three dimensional signal in one to one batch mode
Parameters
| [in] | signal | is the input signal |
|---|---|---|
| [in] | filter | is the signal that shall be flipped for the convolution operation |
| [in] | mode | indicates if the convolution should be expanded or not(where output size equals input) |
| [in] | domain | specifies if the convolution should be performed in frequency os spatial domain |
Returns
the convolved array
Note
The default parameter of domain, AF_CONV_AUTO, heuristically switches between frequency and spatial domain.
Examples
◆ fftConvolve()
C++ Interface for FFT-based convolution any(one through three) dimensional signals.
Parameters
| [in] | signal | is the input signal |
|---|---|---|
| [in] | filter | is the signal that shall be used for the convolution operation |
| [in] | mode | indicates if the convolution should be expanded or not(where output size equals input) |
Returns
the convolved array