fft
→Tensorfft(input: Tensor, n: int | None = None, dim: int = -1, norm: str | None = None)1-D discrete Fourier transform along a single axis.
Computes the one-dimensional DFT of the input tensor along the axis
dim. For an input sequence ,
the output is:
The output bin is the DC component (sum of all samples); through are the positive frequencies; through are the negative frequencies.
Parameters
inputTensornint= NoneNone, the axis length is used as-is.dimint= -1-1
(last axis). Negative indices are supported.normstr or None= None"backward" (default), "forward", or
"ortho". See fftn for the full description.Returns
TensorComplex tensor (complex64) with the same shape as input
except that axis dim has length n (or the original length
when n is None).
Notes
Computational efficiency — under the hood this calls fftn
restricted to one axis, which in turn delegates to the MLX/Accelerate
FFT kernel. For a length- axis where is a power
of two, the Cooley–Tukey radix-2 algorithm is used, reducing the
DFT to .
DC and Nyquist — for an even-length transform of a real signal:
X[0]is real and equals the mean ofxtimes .X[N//2]is real and is the Nyquist component.- All other bins come in conjugate pairs:
X[N-k] == conj(X[k]).
Use rfft to exploit this conjugate symmetry and halve the
output size.
Examples
DFT of a pure cosine at the third harmonic:
>>> N = 16
>>> k0 = 3
>>> n = lucid.arange(N)
>>> # x[n] = cos(2π k0 n / N) — should spike at bins k0 and N-k0
>>> x = lucid.cos(n * (2 * 3.14159 * k0 / N))
>>> X = lucid.fft.fft(x)
>>> X.shape
(16,)
Zero-padding to the next power of two for spectral interpolation:
>>> x = lucid.randn(100)
>>> X = lucid.fft.fft(x, n=128) # pads from 100 → 128
>>> X.shape
(128,)