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

represent random.key_impl of builtin RNGs by canonical string name #24593

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

froystig
Copy link
Member

No great reason to return specs here, and sticking to strings instead can help with simple serialization.

We do not have great reason to return specs here, and sticking to
strings instead can help with simple serialization.
@froystig froystig added the pull ready Ready for copybara import and testing label Oct 29, 2024
@froystig froystig requested a review from jakevdp October 29, 2024 20:08
@froystig froystig self-assigned this Oct 29, 2024
@@ -296,11 +296,12 @@ def split(key: KeyArrayLike, num: int | tuple[int, ...] = 2) -> KeyArray:
def _key_impl(keys: KeyArray) -> PRNGImpl:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _key_impl(keys: KeyArray) -> PRNGImpl:
def _key_impl(keys: KeyArray) -> str | PRNGSpec:

@@ -296,11 +296,12 @@ def split(key: KeyArrayLike, num: int | tuple[int, ...] = 2) -> KeyArray:
def _key_impl(keys: KeyArray) -> PRNGImpl:
assert jnp.issubdtype(keys.dtype, dtypes.prng_key)
keys_dtype = typing.cast(prng.KeyTy, keys.dtype)
return keys_dtype._impl
impl = keys_dtype._impl
return impl.name if impl.name in prng.prngs else PRNGSpec(impl)

def key_impl(keys: KeyArrayLike) -> PRNGSpec:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def key_impl(keys: KeyArrayLike) -> PRNGSpec:
def key_impl(keys: KeyArrayLike) -> str | PRNGSpec:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull ready Ready for copybara import and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants