fn
rfft2
→Tensorrfft2(input: Tensor, s: Sequence[int] | None = None, dim: Sequence[int] = (-2, -1), norm: str | None = None)2-D FFT of a real-valued input over a pair of axes.
Computes the two-dimensional DFT of a real tensor and returns only the non-redundant complex coefficients. For a real input of shape (along the two transformed axes), the output shape is — full along the first transformed axis and compressed along the last.
This is a convenience wrapper around rfftn restricted to
two axes (default: the last two).
Parameters
inputTensorReal-valued input tensor with at least 2 dimensions.
ssequence of int= NoneOutput sizes
(M_out, N_out) along the two transformed axes.
The last value s[-1] is the full signal length along the last
axis before the real FFT; the output last axis will be
s[-1] // 2 + 1. If None, current axis sizes are used.dimsequence of int= (-2, -1)The two axes over which to compute the transform. Default is
(-2, -1). The last element receives the conjugate-symmetry
compression.normstr or None= NoneNormalisation mode —
"backward" (default), "forward", or
"ortho".Returns
TensorComplex tensor (complex64) with the same shape as input
except:
- The first transformed axis has length
s[0](or input size). - The last transformed axis has length .
Notes
Typical use — rfft2 is the standard choice for 2-D image
convolution via the convolution theorem:
where denotes the 2-D DFT. Performing the multiplication in the frequency domain reduces the cost of a full convolution from to .
Examples
2-D real FFT of an image-like tensor:
>>> x = lucid.randn(64, 64)
>>> X = lucid.fft.rfft2(x)
>>> X.shape # last axis: 64 // 2 + 1 = 33
(64, 33)
Round-trip:
>>> x_rec = lucid.fft.irfft2(X, s=[64, 64])
>>> x_rec.shape
(64, 64)