Shortcuts

torch.fft.irfftn

torch.fft.irfftn(input, s=None, dim=None, norm=None, *, out=None)Tensor

Computes the inverse of rfftn().

input is interpreted as a one-sided Hermitian signal in the Fourier domain, as produced by rfftn(). By the Hermitian property, the output will be real-valued.

Note

Some input frequencies must be real-valued to satisfy the Hermitian property. In these cases the imaginary component will be ignored. For example, any imaginary component in the zero-frequency term cannot be represented in a real output and so will always be ignored.

Note

The correct interpretation of the Hermitian input depends on the length of the original data, as given by s. This is because each input shape could correspond to either an odd or even length signal. By default, the signal is assumed to be even length and odd signals will not round-trip properly. So, it is recommended to always pass the signal shape s.

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 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 (Tuple[int], optional) – Dimensions to be transformed. The last dimension must be the half-Hermitian compressed dimension. Default: all dimensions, or the last len(s) dimensions if s is given.

  • norm (str, optional) –

    Normalization mode. For the backward transform (irfftn()), 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 (rfftn()) with the same normalization mode will apply an overall normalization of 1/n between the two transforms. This is required to make irfftn() the exact inverse.

    Default is "backward" (normalize by 1/n).

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example

>>> t = torch.rand(10, 9)
>>> T = torch.fft.rfftn(t)

Without specifying the output length to irfft(), the output will not round-trip properly because the input is odd-length in the last dimension:

>>> torch.fft.irfftn(T).size()
torch.Size([10, 8])

So, it is recommended to always pass the signal shape s.

>>> roundtrip = torch.fft.irfftn(T, t.size())
>>> roundtrip.size()
torch.Size([10, 9])
>>> torch.testing.assert_close(roundtrip, t, check_stride=False)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources