FFT
Fast Fourier Transform operations from mechestim.fft. All FFT
transforms are counted. Real-valued transforms (rfft) cost roughly
half of complex transforms.
Cost Summary
| Operation | Cost Formula |
|---|---|
fft, ifft |
\(5n \cdot \lceil\log_2 n\rceil\) |
fft2, ifft2 |
\(5N \cdot \lceil\log_2 N\rceil\) where \(N = n_1 \cdot n_2\) |
fftn, ifftn |
\(5N \cdot \lceil\log_2 N\rceil\) where \(N = \prod_i n_i\) |
rfft, irfft |
\(5(n/2) \cdot \lceil\log_2 n\rceil\) |
rfft2, irfft2 |
\(5(N/2) \cdot \lceil\log_2 N\rceil\) where \(N = n_1 \cdot n_2\) |
rfftn, irfftn |
\(5(N/2) \cdot \lceil\log_2 N\rceil\) where \(N = \prod_i n_i\) |
hfft, ihfft |
\(5n_{\text{out}} \cdot \lceil\log_2 n_{\text{out}}\rceil\) |
fftfreq, rfftfreq, fftshift, ifftshift |
\(0\) (free) |
Examples
import mechestim as me
with me.BudgetContext(flop_budget=1_000_000) as budget:
signal = me.random.randn(1024) # free
spectrum = me.fft.fft(signal) # 5 * 1024 * 10 = 51,200 FLOPs
freqs = me.fft.fftfreq(1024) # free
print(f"FFT cost: {budget.flops_used:,}") # 51,200
API Reference
mechestim.fft._transforms
FFT transform wrappers with FLOP counting.
Cost model: 5 * N * log2(N) for complex DFT of length N (Cooley-Tukey radix-2). Source: Cooley & Tukey (1965); Van Loan, "Computational Frameworks for the FFT" (1992), §1.4.
fft_cost(n)
FLOP cost of a 1-D complex FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Transform length. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 5 * n * ceil(log2(n)). |
Notes
Source: Cooley & Tukey (1965); Van Loan, Computational Frameworks for the FFT (1992), §1.4. Assumes radix-2 Cooley-Tukey algorithm.
Source code in src/mechestim/fft/_transforms.py
fftn_cost(shape)
FLOP cost of an N-D complex FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple of int
|
Transform shape along each axis. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 5 * N * sum(ceil(log2(d_i))), where N = prod(shape). |
Notes
The multi-dimensional FFT is computed as successive 1-D FFTs along each axis. The cost along axis i is 5 * (N / d_i) * d_i * ceil(log2(d_i)) = 5 * N * ceil(log2(d_i)). Summing over axes gives 5 * N * sum(ceil(log2(d_i))).
Source code in src/mechestim/fft/_transforms.py
hfft_cost(n_out)
FLOP cost of a Hermitian FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_out
|
int
|
Output length. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 5 * n_out * ceil(log2(n_out)). |
Notes
The Hermitian FFT computes the FFT of a signal with Hermitian symmetry, producing real-valued output.
Source code in src/mechestim/fft/_transforms.py
rfft_cost(n)
FLOP cost of a 1-D real FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Input length (real-valued). |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 5 * (n // 2) * ceil(log2(n)). |
Notes
The real FFT exploits conjugate symmetry, roughly halving the work compared to a full complex FFT.
Source code in src/mechestim/fft/_transforms.py
rfftn_cost(shape)
FLOP cost of an N-D real FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple of int
|
Transform shape along each axis. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 5 * (N // 2) * sum(ceil(log2(d_i))), where N = prod(shape). |
Notes
Exploits conjugate symmetry along the last axis, roughly halving the work compared to a full complex N-D FFT.
Source code in src/mechestim/fft/_transforms.py
mechestim.fft._free
Zero-FLOP FFT utility operations.