elegy/hooks.py
def next_rng_key() -> PRNGKey:
    """
    A hook that returns a unique JAX RNG key split from the current global key.

    ```python
    key = elegy.next_rng_key()
    x = jax.random.uniform(key, [])
    ```

    Returns:
        A unique (within a transformed function) JAX rng key that can be used with
        APIs such as ``jax.random.uniform``.
    """
    if LOCAL.contexts:
        context: Context = LOCAL.contexts[-1]
        if context.rng_sequence is not None:
            context: Context = LOCAL.contexts[-1]
            return next(context.rng_sequence)
        else:
            raise ValueError(
                "Cannot execute `rng` not set in context, check init or apply."
            )
    else:
        raise ValueError("Cannot execute `next_rng_key` outside of an `elegy.context`")

    A hook that returns a unique JAX RNG key split from the current global key.

    ```python
    key = elegy.next_rng_key()
    x = jax.random.uniform(key, [])
    ```

    Returns:
        A unique (within a transformed function) JAX rng key that can be used with
        APIs such as ``jax.random.uniform``.
    
A hook that returns a unique JAX RNG key split from the current global key.
A hook that returns a unique JAX RNG key split from the current global key .
def next_rng_key() -> PRNGKey:
    if LOCAL.contexts:
        context: Context = LOCAL.contexts[-1]
        if context.rng_sequence is not None:
            context: Context = LOCAL.contexts[-1]
            return next(context.rng_sequence)
        else:
            raise ValueError(
                "Cannot execute `rng` not set in context, check init or apply."
            )
    else:
        raise ValueError("Cannot execute `next_rng_key` outside of an `elegy.context`")
def next_rng_key ( ) -> PRNGKey : if LOCAL . contexts : context : Context = LOCAL . contexts [ - 1 ] if context . rng_sequence is not None : context : Context = LOCAL . contexts [ - 1 ] return next ( context . rng_sequence ) else : raise ValueError ( "Cannot execute `rng` not set in context, check init or apply." ) else : raise ValueError ( "Cannot execute `next_rng_key` outside of an `elegy.context`" )
A hook that returns a unique JAX RNG key split from the current global key.
A hook that returns a unique JAX RNG key split from the current global key .
"""
    A hook that returns a unique JAX RNG key split from the current global key.

    ```python
    key = elegy.next_rng_key()
    x = jax.random.uniform(key, [])
    ```

    Returns:
        A unique (within a transformed function) JAX rng key that can be used with
        APIs such as ``jax.random.uniform``.
    """
A unique (within a transformed function) JAX rng key that can be used with
APIs such as ``jax.random.uniform``.
A unique ( within a transformed function ) JAX rng key that can be used with APIs such as ` ` jax . random . uniform ` ` .