Add arbitrary-N real FFT via generalized Bruun (z^N-1 factorization)#50
Merged
Conversation
Extend bfft.rfft/irfft to any N >= 2. Power-of-two stays on the native Bruun
kernel; every other size uses a new generalized Bruun plan that factors z^N-1
over the reals -- the 2-adic part reuses the existing power-of-two SIMD cascade,
and each odd prime factor peels off through a condition-1 real radix-p codelet
(z^(pM)-1 = (z^M-1) * prod_{j}(z^(2M) - 2cos(2*pi*j/p) z^M + 1)). FFT-grade for
all N including primes (0.33-2.0x of NumPy/FFTW). Not Bluestein/Rader/mixed-radix.
- src/detail/genbruun_kernel.hpp: bruun::GenBruun (plan-time op schedule, owns
scratch, forward + inverse; rooted pow2 cascades reuse norm_q_fwd/norm_q_inv)
- src/bfft.cpp: bfft_plan is now a tagged {RFFT | GenBruun}; bfft_plan_create
accepts non-pow2; forward/inverse/size/bins dispatch; pow2-only entry points
(native/magnitude/residue/f32) guarded -> BFFT_ERROR_INVALID_ARGUMENT
- bfft/_core.py, bfft/__init__.py: relax N check to N>=2; docstrings
- tests/genbruun_correctness.cpp (+ Makefile): make test now covers arbitrary N
- benchmarks/odd_prime_power_fftw_benchmark.cpp: FFTW-baseline benchmark, all N
- README "Arbitrary-N support"; notes/genbruun_port_handoff.md;
src/detail/genbruun_acceleration_plan.md
- scratch_genbruun*.{cpp,py}: reference implementations
Perf: the arbitrary-N odd-radix projections are not yet SIMD, so non-pow2 sizes
are ~3.5-5x slower than FFTW on prime powers (pow2 path unaffected). The
acceleration plan documents the AVX2/NEON codelet work.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extend bfft.rfft/irfft to any N >= 2. Power-of-two stays on the native Bruun kernel; every other size uses a new generalized Bruun plan that factors z^N-1 over the reals -- the 2-adic part reuses the existing power-of-two SIMD cascade, and each odd prime factor peels off through a condition-1 real radix-p codelet (z^(pM)-1 = (z^M-1) * prod_{j}(z^(2M) - 2cos(2pij/p) z^M + 1)). FFT-grade for all N including primes (0.33-2.0x of NumPy/FFTW). Not Bluestein/Rader/mixed-radix.
Perf: the arbitrary-N odd-radix projections are not yet SIMD, so non-pow2 sizes are ~3.5-5x slower than FFTW on prime powers (pow2 path unaffected). The acceleration plan documents the AVX2/NEON codelet work.