fftn
→Tensorfftn(input: Tensor, s: int | Sequence[int] | None = None, dim: int | Sequence[int] | None = None, norm: str | None = None)N-dimensional discrete Fourier transform.
Computes the N-dimensional discrete Fourier transform (DFT) by applying 1-D FFTs over each of the specified axes in succession. For a single axis of length , the DFT is defined as:
For multiple axes the transforms are applied sequentially, one axis at a time (the final result is equivalent to a single multi-dimensional transform).
The output is always a complex tensor (complex64). Its shape is
identical to input except along the transformed axes, where axis
i has length s[i] when s is provided (the input is
zero-padded or truncated to that size first).
Parameters
inputTensorsint or sequence of int= Nones[i] > input.shape[dim[i]]) or
truncated (if smaller) before the transform. 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= NoneNone.normstr or None= None"backward"(default, same asNone) — forward transform is unscaled; inverse divides by ."forward"— forward transform divides by ; inverse is unscaled."ortho"— both forward and inverse divide by , making the transforms mutually unitary.
Returns
TensorComplex tensor (complex64) with the same shape as input
except that each transformed axis i has length s[i] (or
input.shape[dim[i]] when s is None).
Notes
Frequency ordering — the output follows the standard FFT ordering. For an axis of length , the output bins represent frequencies:
Bins are the non-negative
frequencies; bins
wrap around and represent negative frequencies
. Use fftshift to reorder so that the
zero-frequency bin sits at the centre of each axis.
Autograd — the backward pass computes
where dual swaps "backward" and
"forward" and leaves "ortho" unchanged.
Examples
1-D DFT of a length-8 signal:
>>> x = lucid.fft.fft(lucid.ones(8))
>>> x.shape
(8,)
2-D DFT over the last two axes with explicit output sizes:
>>> x = lucid.ones(4, 4)
>>> X = lucid.fft.fftn(x, s=[8, 8], dim=[-2, -1])
>>> X.shape
(8, 8)
Orthonormal convention (``"ortho"``) makes the transform unitary:
>>> x = lucid.randn(16)
>>> X = lucid.fft.fftn(x, norm="ortho")
>>> # lucid.fft.ifftn(X, norm="ortho") recovers x exactly