-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PCG Random Number Generator #2912
Conversation
* factors seed generation into RandomSupport * takes actual implementation RNG out of Random * adds NBPRandom and PCGRandom that implement RandomStream
This is an intermediate state - we hope to move to PCGRandomStream as the default at some point. This change lets us get started without changing users of the RNGs.
@daviditen can you have an initial look at what I have here? |
David suggested it would be nicer to have one file with sub-modules, so here I rearrange the code to do that.
/* | ||
Generate a seed based on the current time in microseconds as | ||
reported by :proc:`Time.getCurrentTime`, ensuring that it | ||
meets the PRNG's requirements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is out of date, it leaves it to the caller to ensure the seed meets requirements now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to say " Each RNG should adjust a given seed to meet any requirements."
Testing has completed with 6 errors:
These look like minor issues to me but I will work through them. |
I lost the comment about shuffle/permute being on an existing RandomStream. That is OK with me. Since you're touching all the lines in Random.chpl anyway, could you reindent it please? Once you get the testing errors fixed I think this is looking good. |
RandomPrivate_iterate -> NPBRandomPrivate_iterate
|
Passed full testing. @daviditen, care to give the PR a final look over? |
Minor: The method "PCGRandomStream.getNext(min: eltType, max: eltType)" ignores its arguments and does the same thing as the 0-argument version of getNext. Otherwise, I think this is looking very good. |
Previous verison didn't produce a number in a range. Thanks to David for noticing the problem. Also added a test to check the behavior.
Add PCG Random Number Generator * factors seed generation into RandomSupport * takes actual implementation RNG out of Random * sketch interface for RandomStream to be implemented by different generators * adds NPBRandom and PCGRandom that implement RandomStream * adds ldexp function to Math since it is needed to generate a random real from a random int The default RNG is still the NPB one. In the future I hope we will change to the PCG generator since it has better integer support. In addition, we need to be able to name different RNGs intelligently - right now RandomStream is the name of the NPB generator (to avoid making too many changes at once). Reviewed by @daviditen - thanks! Passed full local testing. TODO: I would like for RandomStream to be either a base class or a synonym for the default RNG. Unfortunately, neither of those work right now: * base class -> "Illegal super class" errors, since base class is generic * type RandomStream = PCGRandomStream; causes errors with a type constructor (seems to be missing generic-ness of type).
The default RNG is still the NPB one. In the future I hope we will change
to the PCG generator since it has better integer support. In addition, we need
to be able to name different RNGs intelligently - right now RandomStream
is the name of the NPB generator (to avoid making too many changes
at once).
Reviewed by @daviditen - thanks!
Passed full local testing.
TODO:
I would like for RandomStream to be either a base class or a synonym for the default RNG.
Unfortunately, neither of those work right now:
causes errors with a type constructor (seems to be missing generic-ness of type).