Skip to content

Commit

Permalink
[LSC] change uses of jax.random.KeyArray and jax.random.PRNGKeyArray …
Browse files Browse the repository at this point in the history
…to jax.Array

This change replaces uses of jax.random.KeyArray and jax.random.PRNGKeyArray in the context of type annotations with jax.Array, which is the correct annotation for JAX PRNG keys moving forward.

The purpose of this change is to remove references to KeyArray and PRNGKeyArray, which are deprecated (jax-ml/jax#17594) and will soon be removed from JAX. The design and thought process behind this is described in https://jax.readthedocs.io/en/latest/jep/9263-typed-keys.html.

Note that KeyArray and PRNGKeyArray have always been aliased to Any, so the new type annotation is far more specific than the old one.

PiperOrigin-RevId: 574006700
  • Loading branch information
Jake VanderPlas authored and The etils Authors committed Oct 17, 2023
1 parent 03c3a68 commit ea75b9a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion etils/enp/array_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def from_array(cls, array: Array) -> Optional[ArraySpec]:
if isinstance(array, (np.ndarray, np.generic, ArraySpec)):
shape = array.shape
dtype = array.dtype
elif lazy.has_jax and isinstance(array, lazy.jax.random.PRNGKeyArray):
elif (
lazy.has_jax
and isinstance(array, lazy.jax.Array)
and lazy.jax.dtypes.issubdtype(array.dtype, lazy.jax.dtypes.prng_key)
):
shape = array.shape
dtype = np.uint32 # `jax.random.PRNGKeyArray` is a constant
elif lazy.has_jax and isinstance(
Expand Down

0 comments on commit ea75b9a

Please sign in to comment.