Repository navigation
perf(fft): FFTShift/IFFTShift in one pass, written into the result (#118) - #127
Merged
Merged
Conversation
) shift rolled one axis at a time by slicing it in two halves and Concatenate-ing them the other way round: a full copy per axis plus Concatenate's own overhead (29 allocations, 2.1 MB per 256x256 call). It now computes the roll of every axis at once (an axis given twice is rolled twice, as before and as numpy) and writes each output row from its input row, the innermost axis as two copy() calls, straight into the storage of a ZerosOf result (Data of a contiguous array we own is its storage), so the result is allocated once. Any dtype, through a type switch over the 13. The previous implementation is kept in shift_test.go as the oracle: TestShiftMatchesConcat compares the two over 0-d to 3-D shapes (even, odd, unit and empty axes), axis subsets with negative and repeated axes, float64/int16/complex128/bool and a transposed (non-contiguous) input, both directions; a mutation that drops the innermost roll fails it. cfarm420, one core, three interleaved rounds, load 2.2-2.4, 256x256 float64, every axis: before 206-209 us 2.1 MB 29 allocs after 51-56 us 0.52 MB 9 allocs Refs #118 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FFTShift and IFFTShift shift in one pass (29 -> 9 allocations). The table is measured again on cfarm420 (one pinned core, NumPy 2.5.4, load 2.62 to 3.99, 256 valid rows): 185 slower, 54 faster, 17 tie. The shifts go from 9.7 and 9.9 to 2.0 times NumPy's time. docs/perf.md: Status and the causes list are re-read from this table, and the section on changes since v0.41.0 gains the shift rows and notes the run-to-run spread (for example SubScalar 4.8 to 7.1 on unchanged code). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The 100% coverage gate found nine uncovered blocks in shift: the dtype switch had cases only four dtypes reached in the test, and rollAs had an error branch for ZerosOf that cannot fire (the shape comes from a valid array). TestShiftMatchesConcat now runs every dtype through its own branch, against the old implementation; the unreachable branch is written as the repository writes it elsewhere (ZerosOf(...) // a's shape is valid). Replayed locally with the CI gate's own command (go test -race -coverpkg + covblocks): 0 of 5825 blocks uncovered. Refs #118 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
tannevaled
added a commit
to go-ndarray/docs
that referenced
this pull request
Nov 15, 2026
Every mirrored page, hugo.yaml (version and baseURL /docs/0.45/) and the README now point at v0.45.0. Re-synced from the v0.45.0 source, the only one that changed since v0.44.0: performance.md (docs/perf.md: the table measured at 37c1b86; fft.FFTShift/IFFTShift in one pass). The other mirrored pages are only relabelled. The home page quotes the new counts (185 slower, 54 faster, 17 tied). performance-history.md is left alone. Refs go-ndarray/ndarray#127 Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
tannevaled
added a commit
to go-ndarray/go-ndarray.github.io
that referenced
this pull request
Nov 15, 2026
The card says "library · v0.45.0". The stats and the measured paragraph quote the new table, read from docs/perf-table.md at v0.45.0: 54 faster, 17 tied, 185 slower of 256 (Sum 0.80, fft.FFT 0.52, Ravel 0.36, Real 0.58, SqrtInto 0.50; Exp a tie at 0.98). The playground builds against ndarray v0.45.0; its tests pass. Refs go-ndarray/ndarray#127 Co-authored-by: Claude Sonnet 5.5 <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.
fft.FFTShift/IFFTShiftwere 9.7–9.9× slower than NumPy in the single-core table (#118). They rolled one axis at a time: each axis was sliced in two and joined back withConcatenate, a full copy per axis plusConcatenate's own overhead.Change
copy()calls.ZerosOfresult:Dataof a contiguous array we own is its storage. The result is therefore allocated once and never copied again.Tests
shift_test.goas the oracle.TestShiftMatchesConcatcompares the two over:TestShiftDoesNotAliasItsInput.Measured on cfarm420 (EPYC 7773X): one pinned core, three interleaved rounds, load 2.2–2.4, 256×256 float64, every axis (the table's case).
The allocation counts change, so
perf (refbench CI mode)will ask for a new table run at this head. That run follows in this PR, and the NumPy ratio will come from it.Refs #118
🤖 Generated with Claude Code