package nx

  1. Overview
  2. Docs
N-dimensional arrays for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

raven-1.0.0.alpha3.tbz
sha256=96d35ce03dfbebd2313657273e24c2e2d20f9e6c7825b8518b69bd1d6ed5870f
sha512=90c5053731d4108f37c19430e45456063e872b04b8a1bbad064c356e1b18e69222de8bfcf4ec14757e71f18164ec6e4630ba770dbcb1291665de5418827d1465

doc/nx.core/Nx_core/Rng/index.html

Module Nx_core.RngSource

RNG key utilities.

Splittable RNG keys and implicit key management.

Keys are deterministic integers that can be split to derive independent subkeys. run and with_key install an effect handler that provides implicit key threading via next_key; outside any handler a domain-local auto-seeded generator is used as a convenient fallback.

Keys

Sourcetype key = int

The type for RNG keys.

Sourceval key : int -> key

key seed is a normalized 31-bit non-negative key derived from seed.

Sourceval split : ?n:int -> key -> key array

split ?n k deterministically derives n subkeys from k.

n defaults to 2.

Sourceval fold_in : key -> int -> key

fold_in k data mixes data into k and returns the derived key.

Sourceval to_int : key -> int

to_int k is k as an integer.

Implicit key management

Sourceval next_key : unit -> key

next_key () returns a fresh subkey from the current RNG scope.

Inside a run or with_key block, each call returns a deterministically derived key. Outside any scope, falls back to a domain-local auto-seeded generator (convenient but non-reproducible).

Two calls to next_key () always return different keys.

Sourceval run : seed:int -> (unit -> 'a) -> 'a

run ~seed f executes f in an RNG scope seeded by seed.

Every next_key call within f returns a deterministically derived key. The same seed and the same sequence of next_key calls produce the same keys. Scopes nest: an inner run replaces the outer scope for its duration.

Sourceval with_key : key -> (unit -> 'a) -> 'a

with_key k f executes f in an RNG scope initialized from k.

This is the explicit-key equivalent of run: useful when you have an existing key from a split and want to establish a scope for a sub-computation (e.g. in layer composition).