torch.fft.fft2¶
- torch.fft.fft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) Tensor ¶
Computes the 2 dimensional discrete Fourier transform of
input
. Equivalent tofftn()
but FFTs only the last two dimensions by default.Note
The Fourier domain representation of any real signal satisfies the Hermitian property:
X[i, j] = conj(X[-i, -j])
. This function always returns all positive and negative frequency terms even though, for real inputs, half of these values are redundant.rfft2()
returns the more compact one-sided representation where only the positive frequencies of the last dimension are returned.Note
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater. However it only supports powers of 2 signal length in every transformed dimensions.
- Parameters
input (Tensor) – the input tensor
s (Tuple[int], optional) – Signal size in the transformed dimensions. If given, each dimension
dim[i]
will either be zero-padded or trimmed to the lengths[i]
before computing the FFT. If a length-1
is specified, no padding is done in that dimension. Default:s = [input.size(d) for d in dim]
dim (Tuple[int], optional) – Dimensions to be transformed. Default: last two dimensions.
norm (str, optional) –
Normalization mode. For the forward transform (
fft2()
), these correspond to:"forward"
- normalize by1/n
"backward"
- no normalization"ortho"
- normalize by1/sqrt(n)
(making the FFT orthonormal)
Where
n = prod(s)
is the logical FFT size. Calling the backward transform (ifft2()
) with the same normalization mode will apply an overall normalization of1/n
between the two transforms. This is required to makeifft2()
the exact inverse.Default is
"backward"
(no normalization).
- Keyword Arguments
out (Tensor, optional) – the output tensor.
Example
>>> x = torch.rand(10, 10, dtype=torch.complex64) >>> fft2 = torch.fft.fft2(x)
The discrete Fourier transform is separable, so
fft2()
here is equivalent to two one-dimensionalfft()
calls:>>> two_ffts = torch.fft.fft(torch.fft.fft(x, dim=0), dim=1) >>> torch.testing.assert_close(fft2, two_ffts, check_stride=False)