mirror of
https://github.com/ROCm/jax.git
synced 2025-04-24 06:36:05 +00:00

A PRNG implementation is determined by a key shape and a set of basic functions on such a key: seed, split, random_bits, and fold_in. A PRNG implementation can then by lifted to an array-of-keys-like object. Namely, a new internal pytree class PRNGKeyArray wraps the implementation and maintains an array of keys of the right shape. This array-like object is the new "key" that gets passed around the various functions in the public random API (e.g. `random.uniform`, `random.normal`, ...). So the PRNGKeyArray class really serves two purposes at once: 1. To adapt key implementations into "arrays" of such keys. 2. To carry a reference to the PRNG implementation around and delegate back to it from the functions in random.
23 lines
693 B
Python
23 lines
693 B
Python
# Copyright 2021 Google LLC
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# flake8: noqa: F401
|
|
|
|
from jax._src.prng import (
|
|
threefry2x32_p,
|
|
threefry_2x32,
|
|
PRNGImpl,
|
|
seed_with_impl,
|
|
)
|