dconv¶
- dnois.fourier.dconv(f1: Tensor, f2: Tensor, dims: Sequence[int] = None, out: Literal['full', 'same', 'valid'] = 'full', padding: int | Sequence[int] | str = 'linear', real: bool = None) Tensor ¶
Computes n-D discrete convolution for two tensors \(f_1\) and \(f_2\) utilizing FFT.
In each involved dimension, the lengths of \(f_1\), \(N\) and \(f_2\), \(M\) can be different. In that case, the shorter sequence will be padded first to match length of the longer one. Notably, it is circular convolution that is computed without additional padding (if
padding
is0
,circular
ornone
). Specifypadding
aslinear
or \(\min(N,M)-1\) to compute linear convolution, with extra computational overhead.padding
can also be set as a non-negative integer within this range for a balance. Note that the lengths of each dimension can be different.See Convolution for examples.
See also
This function is similar to scipy.signal.fftconvolve when
padding
islinear
.dconv1()
anddconv2()
are 1D and 2D variants, respectively, with slightly different signature.conv()
provides more functionalities.- Parameters:
f1 (Tensor) – The first tensor \(f_1\).
f2 (Tensor) – The second tensor \(f_2\).
dims (Sequence[int]) – The dimensions to be convolved. Default: the last
ndim
dimensions wherendim
is the fewer number of dimensions off1
andf2
out (str) –
One of the following options. Default:
full
. In each dimension:full
Return complete result so the size of each dimension is
max(N, M) + padding
.same
Return the middle segment of result. In other words, drop the first
min(N, M) // 2
elements and return subsequentmax(N, M)
ones. If the length is less thanmax(N, M)
after dropping, the elements from head will be appended to reach this length.valid
Return only the segments where
f1
andf2
overlap completely so the size of each dimension is \(\max(N,M)-\min(N,M)+1\).
padding (int, Sequence[int] or str) – Padding amount in all dimensions. See description above. Default:
linear
.real (bool) – If both
f1
andf2
are real-valued andreal
isTrue
,torch.fft.rfft()
can be used to improve computation and a real-valued tensor will be returned. If eitherf1
orf2
is complex orreal=False
, a complex tensor will be returned. Default: depending on the dtype off1
andf2
.
- Returns:
Convolution between
f1
andf2
. Complex if eitherf1
orf2
is complex orreal=False
, real-valued otherwise.- Return type:
Tensor