Repository navigation
feat(random): allocation-free scalar draws (Float64, FillUniform, IntN, FillIntN, ShuffleInt64) - #84
Merged
Merged
Conversation
Float64, FillUniform, IntN, FillIntN and ShuffleInt64, for solvers that draw a few values per step (differential evolution, basin hopping). Each consumes exactly the bit-generator output NumPy 2.5.3 consumes for the same call (Generator: Lemire bounded integers, non-negative uniform range; RandomState: masked rejection, uniform accepts high < low) and allocates nothing. Tested against NumPy 2.5.3 (x86-64, in an amd64 container): 7296 calls on 192 scripts, errors included, mixed 32/64-bit draws on PCG64; planted breaks; AllocsPerRun = 0; fuzz on NaN/Inf/negative/zero/MinInt64/MaxInt64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Nov 1, 2026
* perf: float32 Exp and Log on the float64 kernels (2-3.5x faster) float32 Exp and Log called math.Exp/math.Log per element, 6-14x slower than NumPy on one Zen 3 core. They now run this package's float64 kernels (the Arm optimized-routines ports) 256 elements at a time through a stack buffer, rounding each result once: within 0.5 + 2^-29 float32 ULP, no allocation. abbench, 8 rounds, one Zen 3 core: Exp 297 -> 84 us and Log 198 -> 99 us at 16 Ki; Exp 18.8 -> 5.2 ms and Log 12.4 -> 6.1 ms at 1 Mi. Still about 3x slower than NumPy's float32 SIMD, recorded as an open defect in docs/perf.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: the float32 Exp/Log release is v0.31.0 (v0.30.0 was taken by #84) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 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.
What
Task 1 of
docs/design-global.mdin go-numerics/optimize (section 2.3): allocation-free scalar draws onrandom.Generatorandrandom.RandomState:Float64,FillUniform,IntN,FillIntN,ShuffleInt64.Each consumes exactly the bit-generator output NumPy 2.5.3 consumes for the same call and allocates nothing on its success path.
Sources opened (NumPy v2.5.3)
_generator.pyx(uniform,shuffle,_shuffle_raw),mtrand.pyx(uniform,randint,shuffle,_shuffle_raw),_bounded_integers.pyx.in(_rand_int64: the scalar and sized paths both callrandom_bounded_uint64_fill),distributions.c(random_uniform,random_interval,random_bounded_uint64_fill).Semantics:
Generator.FillUniformrejects a negative, NaN or infinitehigh-low; the legacy one rejects only NaN or infinite (high < lowis accepted).Generator.IntNuses Lemire,RandomState.IntNmasked rejection.IntNpanics onhigh <= 0(likemath/rand);FillIntNreturns an error and draws nothing, except for an emptydst, as NumPy returns the empty array first.Validation
testdata/scalar.py+TestScalarDrawsMatchNumPy: 7296 calls on 192 scripts (48 seeds x Generator/PCG64, Generator/MT19937, RandomState/MT19937, RandomState/PCG64), 760 of them errors on both sides, mixed 32/64-bit draws (PCG64 half-word buffering). Fixture made by an x86-64 NumPy 2.5.3 in an amd64 container (GONDARRAY_REGEN=1 go test ./random -run TestRegenerateScalarFixture; no Rosetta here, and aarch64 NumPy fusesuniform).TestScalarAllocations:testing.AllocsPerRun= 0 for every method, 4 generators, all bounded-integer branches.FuzzScalarDraws(NaN, +-Inf, negative/zero bounds, MinInt64/MaxInt64, 2^32 boundaries): 8M execs clean.randompackage coverage 100.0%.scalar_bench_test.go); numbers are not published: the host load was above 30 while this was written.README and
docs/random.mdupdated; landing and docs site follow in their own PRs.🤖 Generated with Claude Code