Repository navigation
Conversation
…cting 28 bit draws
This branch has not been deployed
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.
Sampling a random
PrimeFieldelement drawsrng.next_u32() >> 4, a 28 bit number, and throws it away unless it's belowP. That looks like it came from a field close to 2^31. For the Pluto primes it means 1 in about 2.6 million draws is accepted forPlutoBaseFieldand 1 in about 16 million forPlutoScalarField, and everyrng.gen::<PrimeField<P>>()in the crate and its tests pays for that.It changes the following:
samplenow usesrng.gen_range(0..P), which is still uniform and rejects as few draws as it can. There's a new test that draws 1000 * P elements in both Pluto fields and checks that every value comes up about 1000 times.In a release build one draw took 38 ms for
PlutoScalarFieldand 4.8 ms forPlutoBaseFieldon main, and takes 29 ns and 16 ns with this change. The new test runs in 0.1 s here, on main it would take around 20 minutes even in a release build.This is the fix I mentioned in #258, after this the commitments there could go back to
rng.gen().