dpnp.convolve
- dpnp.convolve(a, v, mode='full', method='auto')[source]
Returns the discrete, linear convolution of two one-dimensional sequences. The convolution operator is often seen in signal processing, where it models the effect of a linear time-invariant system on a signal [1]. In probability theory, the sum of two independent random variables is distributed according to the convolution of their individual distributions.
If v is longer than a, the arrays are swapped before computation.
For full documentation refer to
numpy.convolve
.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- First input array.
v ({dpnp.ndarray, usm_ndarray}) -- Second input array.
mode ({'full', 'valid', 'same'}, optional) --
'full': This returns the convolution at each point of overlap, with an output shape of (N+M-1,). At the end-points of the convolution, the signals do not overlap completely, and boundary effects may be seen.
'same': Mode 'same' returns output of length
max(M, N)
. Boundary effects are still visible.'valid': Mode 'valid' returns output of length
max(M, N) - min(M, N) + 1
. The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.Default:
'full'
.
method ({'auto', 'direct', 'fft'}, optional) --
'direct': The convolution is determined directly from sums.
'fft': The Fourier Transform is used to perform the calculations.
This method is faster for long sequences but can have accuracy issues.
'auto': Automatically chooses direct or Fourier method based on
an estimate of which is faster.
Note: Use of the FFT convolution on input containing NAN or INF will lead to the entire output being NAN or INF. Use
method='direct'
when your input contains NAN or INF values.Default:
'auto'
.
- Returns:
out -- Discrete, linear convolution of a and v.
- Return type:
dpnp.ndarray
See also
dpnp.correlate
Cross-correlation of two 1-dimensional sequences.
Notes
The discrete convolution operation is defined as
\[(a * v)_n = \sum_{m = -\infty}^{\infty} a_m v_{n - m}\]It can be shown that a convolution \(x(t) * y(t)\) in time/space is equivalent to the multiplication \(X(f) Y(f)\) in the Fourier domain, after appropriate padding (padding is necessary to prevent circular convolution). Since multiplication is more efficient (faster) than convolution, the function implements two approaches - direct and fft which are regulated by the keyword method.
References
Examples
Note how the convolution operator flips the second array before "sliding" the two across one another:
>>> import dpnp as np >>> a = np.array([1, 2, 3], dtype=np.float32) >>> v = np.array([0, 1, 0.5], dtype=np.float32) >>> np.convolve(a, v) array([0. , 1. , 2.5, 4. , 1.5], dtype=float32)
Only return the middle values of the convolution. Contains boundary effects, where zeros are taken into account:
>>> np.convolve(a, v, 'same') array([1. , 2.5, 4. ], dtype=float32)
The two arrays are of the same length, so there is only one position where they completely overlap:
>>> np.convolve(a, v, 'valid') array([2.5], dtype=float32)