fft
22 memberslucid.fftlucid.fft — discrete Fourier transform ops.
Mirrors the standard FFT surface: 18 transform variants
(fft / ifft / fft2 / ifft2 / fftn / ifftn and the
r- and h-prefixed counterparts) plus the four utility helpers
fftfreq / rfftfreq / fftshift / ifftshift.
Backend: every transform delegates to mlx::core::fft through the four
engine primitives _C_engine.fft.{fftn,ifftn,rfftn,irfftn}. MLX
itself wraps Apple Accelerate vDSP under the hood, so both Device::CPU
and Device::GPU tensors land on the same fast CPU FFT kernel — see
lucid/_C/ops/fft/_Detail.h for the carve-out rationale.
Normalisation: matches the standard convention. norm='backward' (the
default) leaves fft unscaled and divides ifft by N;
norm='forward' swaps those; norm='ortho' divides both by
sqrt(N). MLX's transforms always produce the 'backward' form,
so non-default norms are reached by post-multiplying the result.
Autograd: the base ops are lucid.autograd.Function subclasses, in
_transforms. The backward of every transform is the dual
transform with the dual normalisation (backward ↔ forward,
ortho ↔ ortho), taken at the transform size and then cropped or
zero-padded back to the input's size along every transformed axis — the
adjoint of what n / s does to the input. The dual is itself
taken through its Function, so a gradient differentiates again under
create_graph.
Input: an integer or boolean tensor is promoted to the default floating
dtype, and with dim omitted an s shorter than the rank names the
last len(s) axes.
Functions
fftn→ TensorN-dimensional discrete Fourier transform.
ifftn→ TensorN-dimensional inverse discrete Fourier transform.
fft→ Tensor1-D discrete Fourier transform along a single axis.
ifft→ Tensor1-D inverse discrete Fourier transform along a single axis.
fft2→ Tensor2-D discrete Fourier transform over a pair of axes.
ifft2→ Tensor2-D inverse discrete Fourier transform over a pair of axes.
rfftn→ TensorN-dimensional FFT of a real-valued input, exploiting conjugate symmetry.
irfftn→ TensorN-dimensional inverse FFT for a Hermitian-symmetric spectrum.
rfft→ Tensor1-D FFT of a real-valued input along a single axis.
irfft→ Tensor1-D inverse FFT for a Hermitian-symmetric spectrum.
rfft2→ Tensor2-D FFT of a real-valued input over a pair of axes.
irfft2→ Tensor2-D inverse FFT for a Hermitian-symmetric spectrum.
hfftn→ TensorN-dimensional FFT of a Hermitian-symmetric complex signal.
ihfftn→ TensorN-dimensional inverse FFT of a real-valued signal, giving a Hermitian output.
hfft→ Tensor1-D FFT of a Hermitian-symmetric complex signal.
ihfft→ Tensor1-D inverse FFT of a real signal, giving a Hermitian half-spectrum.
hfft2→ Tensor2-D FFT of a Hermitian-symmetric complex signal over a pair of axes.
ihfft2→ Tensor2-D inverse FFT of a real signal, giving a Hermitian half-spectrum.
fftfreq→ TensorFrequency bin centres for the output of fft / fftn.
rfftfreq→ TensorFrequency bin centres for the output of rfft / rfftn.
fftshift→ TensorShift the zero-frequency component to the centre of the spectrum.
ifftshift→ TensorUndo the zero-frequency centring performed by fftshift.