fn

irfftn

Tensor
irfftn(input: Tensor, s: int | Sequence[int] | None = None, dim: int | Sequence[int] | None = None, norm: str | None = None)
source

N-dimensional inverse FFT for a Hermitian-symmetric spectrum.

Computes the inverse N-dimensional FFT assuming the input is conjugate-symmetric (Hermitian), as produced by rfftn. The output is guaranteed to be real-valued.

For the last transformed axis, the full-length signal size must be specified or inferred: given an input last-axis of length m=N/2+1m = \lfloor N/2 \rfloor + 1, the default assumed full length is N=2(m1)N = 2(m - 1) (even). Supply s[-1] explicitly when the original signal length was odd.

Parameters

inputTensor
Complex Hermitian tensor (frequency domain) of any shape, typically the output of rfftn.
sint or sequence of int= None
Full output signal length(s) along each transformed axis. The last element is the real (time-domain) length of the last transformed axis. For all other axes s[i] may equal the corresponding input axis length. If None, the last axis output length defaults to 2(m1)2 (m - 1) where mm is the input last-axis length; all other axes keep their input sizes.
dimint or sequence of int= None
Axis or axes over which to compute the inverse transform. Defaults to all axes.
normstr or None= None
Normalisation mode — "backward" (default), "forward", or "ortho". See fftn for the full description.

Returns

Tensor

Real tensor (float32) whose shape matches input except:

  • The last transformed axis has length s[-1] (or 2(m1)2(m-1) by default, where mm is the input last-axis length).
  • All other transformed axes have lengths s[i] (or input sizes when s is None).

Notes

Specifying odd-length signals — if the original real signal had an odd length NN (so the rfft output had (N+1)/2(N+1)/2 bins), you must pass s=[N] explicitly. Without it the default 2(m1)2(m-1) rule would give N1N-1 (even), producing the wrong output length.

Round-trip — for a real tensor x:

irfftn(rfftn(x,norm=m),s,norm=m)x\text{irfftn}(\text{rfftn}(x, \text{norm}=m), s, \text{norm}=m) \approx x

where s should contain the original axis sizes to avoid the even/odd ambiguity.

Examples

Round-trip through the real FFT:
>>> x = lucid.randn(128)
>>> X = lucid.fft.rfftn(x)
>>> X.shape
(65,)
>>> x_rec = lucid.fft.irfftn(X, s=[128])
>>> x_rec.shape
(128,)
3-D round-trip:
>>> x = lucid.randn(16, 32, 64)
>>> X = lucid.fft.rfftn(x)
>>> x_rec = lucid.fft.irfftn(X, s=[16, 32, 64])
>>> x_rec.shape
(16, 32, 64)