torch.fft.irfft2
- torch.fft.irfft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) →
Computes the inverse of rfft2().
Equivalent to irfftn() but IFFTs only the last two dimensions by default.
input is interpreted as a one-sided Hermitian signal in the Fourier
domain, as produced by rfft2(). By the Hermitian property, the
output will be real-valued.
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 length s[i] before computing the real FFT.
If a length -1 is specified, no padding is done in that dimension.
Defaults to even output in the last dimension:
s[-1] = 2*(input.size(dim[-1]) - 1).
dim () – Dimensions to be transformed. The last dimension must be the half-Hermitian compressed dimension. Default: last two dimensions.
>>> t = torch.rand(10, 9)
>>> T = torch.fft.rfft2(t)
Without specifying the output length to irfft2(), the output
will not round-trip properly because the input is odd-length in the last
dimension:
>>> torch.fft.irfft2(T).size()
torch.Size([10, 8])
So, it is recommended to always pass the signal shape s.
>>> roundtrip = torch.fft.irfft2(T, t.size())
>>> roundtrip.size()
torch.Size([10, 9])
>>> torch.testing.assert_close(roundtrip, t, check_stride=False)
norm (str, optional) –
Normalization mode. For the backward transform
(irfft2()), these correspond to:
"forward" - no normalization
"backward" - normalize by 1/n
"ortho" - normalize by 1/sqrt(n) (making the real IFFT orthonormal)
Where n = prod(s) is the logical IFFT size.
Calling the forward transform (rfft2()) with the same
normalization mode will apply an overall normalization of 1/n between
the two transforms. This is required to make irfft2()
the exact inverse.
Default is "backward" (normalize by 1/n).
out (Tensor, optional) – the output tensor.