The DFT on Gen2+
Run a Fourier transform on the NPU, batch many transforms in one call, compute the inverse with the same operation, and know what the emulator can tell you about accuracy.
Tested on the toolkit 2.5.0 CPU emulator with Python 3.12 on 18 November 2026.
Toolkit 2.5.0 adds a new native operation for NPU Gen2+: the discrete Fourier transform (DFT). Q.ANT unveiled Gen2+ on 17 November 2026 and describes it as computing the DFT optically, in a single pass of light, instead of as a sequence of electronic calculations.
The DFT turns a signal into its frequencies. It sits at the heart of signal processing, and Q.ANT also uses it to replace an attention layer in a large language model, which they demonstrated alongside a GPU at SC26.
Run your first DFT
The DFT works on complex numbers, so it uses a new data type, bcomplex32. Each value holds a bfloat16 real part and a bfloat16 imaginary part, 4 bytes in total. It comes from the ml_dtypes package, version 0.6.0 or newer.
import numpy as np
from ml_dtypes import bcomplex32
import qant_native_computing_toolkit as q
x = np.exp(2j * np.pi * 3 * np.arange(8) / 8) # a wave that repeats 3 times in 8 samples
X = q.native.dft(x.astype(bcomplex32)).astype(np.complex64)
print(np.round(np.abs(X), 2))
On the CPU emulator this prints:
[0. 0. 0. 8. 0. 0. 0. 0.]
All of the signal lands in bin 3, its frequency. The value is 8, not 1, because the toolkit computes the unnormalised DFT, the same convention as np.fft.fft.
What dft accepts
| Argument | Meaning |
|---|---|
data | An array with at least one dimension, of dtype bcomplex32. The transform runs along the last axis. |
device_id | Optional. -1, the default, picks the first NPU that supports the DFT. |
| Result | Same shape as the input, dtype bcomplex32. Bins are in NumPy’s FFT order: 0, then positive, then negative frequencies. |
Any leading axes are batch dimensions, so one call can run many transforms:
batch = np.random.default_rng(0).standard_normal((4, 256)).astype(bcomplex32)
spectra = q.native.dft(batch) # four DFTs of length 256, shape (4, 256)
Compute the inverse DFT
The NPU only has a forward DFT, but the inverse follows from it with two complex conjugations:
IDFT(X) = conj(DFT(conj(X))) / N
def idft(X):
n = X.shape[-1]
y = q.native.dft(np.conj(X).astype(bcomplex32)).astype(np.complex64)
return np.conj(y) / n
Applied to the spectrum from the first example, idft(X) returns the original wave. The official signal denoising example uses this trick for its round trip.
Which devices run the DFT
The DFT runs on Gen2+ devices only. Check with the capability functions:
print(q.generic.get_available_npus([q.generic.QantDeviceCapability.Dft]))
On the emulator this prints the three simulated Gen2+ devices:
[(10, 'cpu_backend_gen2p_10'), (11, 'cpu_backend_gen2p_11'), (12, 'cpu_backend_gen2p_12')]
| What you try | What happens |
|---|---|
dft on a Gen2 device, for example device_id=0 | RuntimeError: ... NPU0 does not support DFT |
A Gen2 operation such as linear_fprop on device 10 | RuntimeError: ... NPU10 does not support MULTIPLICATION |
A complex64 array instead of bcomplex32 | TypeError: data must be of dtype <class 'ml_dtypes.bcomplex32'> but is complex64 |
| A 0-dimensional array | ValueError: data must have at least one dimension |
Accuracy on the emulator
The emulator computes the DFT with an exact FFT from the Rust rustfft library, with every step in bfloat16. We compared it with NumPy’s FFT on random complex inputs:
| Length | 8 | 64 | 256 | 1,024 | 4,096 | 100 | 127 | 1,000 |
|---|---|---|---|---|---|---|---|---|
| Relative error | 0.2% | 0.5% | 0.7% | 0.7% | 0.8% | 0.9% | 1.4% | 0.9% |
Lengths that aren’t powers of two work too, with a little more error for awkward lengths such as the prime 127. Overall the error grows slowly with length, because a longer transform rounds more intermediate results. This is bfloat16 arithmetic on a CPU. It tells you nothing about the noise of the optical transform on a card. See Emulator and hardware.
Further reading
- Q.ANT unveils NPU Gen 2+, the announcement from 17 November 2026
- Computing Attention with Light, Q.ANT’s whitepaper on running LLM attention with a photonic accelerator alongside a GPU
- Release v2.5.0, the toolkit release that added the DFT
What’s next
- Run the signal denoising example.
- See where the DFT sits in the stack in How the toolkit is built.