rfftn
→Tensorrfftn(input: Tensor, s: int | Sequence[int] | None = None, dim: int | Sequence[int] | None = None, norm: str | None = None)N-dimensional FFT of a real-valued input, exploiting conjugate symmetry.
When the input is real, its N-dimensional DFT satisfies the Hermitian (conjugate-symmetric) property:
Only the non-redundant half of the spectrum along the last transformed axis needs to be stored. For a last-axis length , the output contains only unique complex values along that axis. All other axes are full-length ( bins each).
Parameters
inputTensorsint or sequence of int= Nones[-1] determines the last-axis size before the
real FFT; the output last axis will be s[-1] // 2 + 1.
len(s) must equal len(dim) when both are sequences.
If None, each axis is transformed at its current size.dimint or sequence of int= Nonedim is the axis that gets the conjugate-symmetry
compression. Defaults to all axes when None.normstr or None= None"backward" (default), "forward", or
"ortho". is the product of the full (uncompressed)
lengths of all transformed axes.Returns
TensorComplex tensor (complex64) with the same shape as input
except:
- All transformed axes except the last have their original lengths
(or
s[i]when specified). - The last transformed axis has length .
Notes
Why n//2 + 1? — A real-to-complex 1-D DFT of length has the symmetry . The unique bins are therefore , giving complex values. For even this is ; for odd it is .
Nyquist theorem — for a real discrete signal sampled at rate , the highest representable frequency is the Nyquist frequency . The bin at index corresponds exactly to this frequency. Any signal energy above aliases back into the range — this is the aliasing artefact that the sampling theorem warns against.
Memory saving — compared to fftn, rfftn stores
roughly half the complex coefficients along the last axis, reducing
peak memory and compute by ~2× for large real tensors.
Examples
1-D real FFT:
>>> x = lucid.randn(128)
>>> X = lucid.fft.rfftn(x)
>>> X.shape # 128 // 2 + 1 = 65
(65,)
3-D real FFT over all axes:
>>> x = lucid.randn(16, 32, 64)
>>> X = lucid.fft.rfftn(x)
>>> X.shape # last axis: 64 // 2 + 1 = 33
(16, 32, 33)
Explicit output size for zero-padding:
>>> X = lucid.fft.rfftn(lucid.randn(60), s=[64])
>>> X.shape # 64 // 2 + 1 = 33
(33,)