Repository navigation
perf(random): Choice gathers without allocating per element - #115
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-D array Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Nov 15, 2026
…udit entries docs/linalg.md and docs/design-linalg.md named the ndarray package's own GEMM; since #122 it is go-blas/blas. SECURITY.md: the go-blas entry is v0.42.0 (#122, commit 208bdac, tag v0.42.0 contains it); the Choice gather entry is v0.40.2 (#115, 8ac94fb, first tag containing it, Refs #103). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Nov 15, 2026
… v0.23.0; Round is half to even, add RoundHalfAway (#123) * perf: float64 Abs, Neg, Square, Floor, Ceil on go-simd/floats v0.23.0 kernels Bump go-simd/floats to v0.23.0 and route the contiguous float64 case of Abs, Neg, Square, Floor and Ceil through its SIMD kernels, still split across cores above kernels.ParThreshold. Results are bit for bit those of math.Abs, -x, x*x, math.Floor and math.Ceil (a signalling NaN may come back quieted). Round is unchanged: it rounds half away from zero, which floats.RoundEven does not. On 10^5 float64, one core of cfarm420: Abs 244-258 -> 70-75 us, Neg 243-249 -> 72-75, Square 243-247 -> 72-80, Floor 432-457 -> 73-81, Ceil 437-464 -> 72-81 (result allocation included). Refs #118 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * docs: GEMM now in go-blas/blas; release tags for the two unreleased audit entries docs/linalg.md and docs/design-linalg.md named the ndarray package's own GEMM; since #122 it is go-blas/blas. SECURITY.md: the go-blas entry is v0.42.0 (#122, commit 208bdac, tag v0.42.0 contains it); the Choice gather entry is v0.40.2 (#115, 8ac94fb, first tag containing it, Refs #103). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * feat!: Round is half to even (np.round) on the RoundEven kernel; add RoundHalfAway Round now rounds exact halves to the even neighbour on every dtype (float64 on the go-simd/floats RoundEven kernel; float32 and each part of a complex number through math.RoundToEven), as np.round with no decimals. The old half-away-from-zero behaviour (math.Round) is RoundHalfAway, on the scalar path, on the same dtypes. Integers and bools are unchanged by both. There is no decimals variant. Tests: halves and the edge table for both against math.RoundToEven and math.Round; Abs and Neg now compared with strict NaN bits, the others with is-NaN only. On 10^5 float64, cfarm420 one core: Round 325-340 -> 71-80 us; RoundHalfAway (control) 324-345 us. Refs #118 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * docs: exempt Array.RoundHalfAway from the perf table (no NumPy counterpart) TestPerf requires every public function to have a row or an exemption. RoundHalfAway rounds halves away from zero; np.round is half to even, which is Array.Round, so there is nothing to time it against. Refs #118 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- 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.
Generator.Choice,RandomState.Choiceandrandom.Choiceallocated twice per drawn element. The gather (takeAxis) slicedreflect.Values for every index, and eachValue.Sliceallocates. It now copies whole slabs through a byte view of the source and the result: one code path for all 13 dtypes, none of which hold pointers.Closes #103
Allocations for 100 000 draws from a 1000-element array, from
go test -run TestPerf -perf.record(exact under any load;docs/perf.jsonanddocs/perf-table.mdare updated):random.Generator.Choicerandom.RandomState.Choicerandom.ChoiceNumPy makes one allocation (the result); the 12–13 left are the fixed cost of the index draw and the result array. Timing is deferred: the 1-minute load here was 11, above the harness's limit of 8.
TestChoiceAllocsConstant: 100 and 10 000 draws must cost the same number of allocations, along axis 0 of a 1-D array and along axis 1 of a 2-D one. On the old code it fails with 213 vs 20 013 and 2 014 vs 200 014.random/numpy_test.gopass.randomstays at 100 % statement coverage.unsafe.Sliceview.🤖 Generated with Claude Code