Skip to content
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

Closes #3008: Add generator sym entry and stateful uniform distribution #3016

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

stress-tess
Copy link
Member

This PR (closes #3008) adds a generator sym entry to the symbol table. It also add a stateful uniform distribution. So repeated method calls won't return the same array with a set seed, but a new generator with the same seed will produce the same sequence of random arrays. It updates the methods which draw a from a uniform distribution to use the stateful variant

Example:

>>> rng = ak.random.default_rng(74)

>>> rng.integers(0, 2**32, size=3, dtype="uint")
array([103369013 434448015 1372864948])

>>> rng.uniform(-1.0, 1.0, size=3)
array([-0.31903782753174481 0.35896419541356117 0.45980632831507906])

>>> rng.integers(0, 1, size=5, dtype="bool")
array([False True False True True])

>>> rng.integers(-(2**32), 2**32, size=3, dtype="int")
array([-83456679 -540246299 -3756329859])

# repeat
>>> rng = ak.random.default_rng(74)

>>> rng.integers(0, 2**32, size=3, dtype="uint")
array([103369013 434448015 1372864948])

>>> rng.uniform(-1.0, 1.0, size=3)
array([-0.31903782753174481 0.35896419541356117 0.45980632831507906])

>>> rng.integers(0, 1, size=5, dtype="bool")
array([False True False True True])

>>> rng.integers(-(2**32), 2**32, size=3, dtype="int")
array([-83456679 -540246299 -3756329859])

Its adds tests for this functionality. Note the tests for the legacy functions are copied over from the existing ones in pdarraycreation

@stress-tess
Copy link
Member Author

I forgot there's been changes to the chpl random module in recent versions, I'll need to make this compatible with chpl 1.31 and 1.32

@stress-tess
Copy link
Member Author

I did my best updating the random compat modules, but that was mostly just me loosening the memory management requirements to make the errors go away lol. @jeremiah-corrado seems to have touched those wouldn't mind double checking my work I'd appreciate it

@stress-tess stress-tess marked this pull request as ready for review March 4, 2024 17:26
Copy link
Contributor

@jeremiah-corrado jeremiah-corrado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just the one question about an extra array copy in the compat modules:

src/compat/e-132/ArkoudaRandomCompat.chpl Outdated Show resolved Hide resolved
Copy link
Contributor

@ajpotts ajpotts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions, as marked, but otherwise looks good!

arkouda/random/_generator.py Show resolved Hide resolved
tests/random_test.py Show resolved Hide resolved
PROTO_tests/tests/random_test.py Show resolved Hide resolved
Copy link
Contributor

@ajpotts ajpotts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Contributor

@jaketrookman jaketrookman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Pierce Hayes and others added 2 commits March 12, 2024 18:17
…distribution

This PR (closes Bears-R-Us#3008) adds a generator sym entry to the symbol table. It also add a stateful uniform distribution i.e. repeated method calls won't return the same array with a set seed, but a new generator with the same seed will produce the same sequence of random arrays

updated compat modules for backwards compatibility with chpl 1.32/1.31
@stress-tess stress-tess merged commit 064d2c2 into Bears-R-Us:master Mar 12, 2024
13 checks passed
@stress-tess stress-tess deleted the 3008_generator_sym_entry branch March 12, 2024 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add generator sym entry and stateful uniform distribution
4 participants