Table of Contents

Class MT19937.State

Namespace
NumSharp
Assembly
NumSharp.dll

The MT19937 state — NumPy's {'bit_generator': 'MT19937', 'state': {'key': uint32[624], 'pos': int}} with the nested 'state' dict flattened.

public class MT19937.State : BitGeneratorState
Inheritance
MT19937.State
Inherited Members

Remarks

Unsealed, so a subclass engine that adds state of its own derives its snapshot from this class. Its GetStateCore() override returns the derived snapshot, which passes the typed state getter (a cast to MT19937.State) and SetStateCore(BitGeneratorState) (an is State test); its SetStateCore(BitGeneratorState) override restores its own fields and calls the base for the engine's. Footgun: the bit_generator label stays "MT19937" and the base SetStateCore(BitGeneratorState) takes any MT19937.State, where NumPy labels a subclass's state with the subclass's class name and refuses another class's state.

Constructors

State()

Creates an empty state (fill key and pos before assigning it).

public State()

State(uint[], int)

Creates a state from a key and a position.

public State(uint[] key, int pos)

Parameters

key uint[]

The 624-word key (copied by reference; the setter copies its first 624 words).

pos int

The index of the next word to temper, in [0, 624].

Properties

bit_generator

NumPy's 'bit_generator' key: the name of the bit generator class this state belongs to.

public override string bit_generator { get; }

Property Value

string

key

The 624-word key (NumPy state['state']['key']).

public uint[] key { get; set; }

Property Value

uint[]

pos

The index of the next word to temper (NumPy state['state']['pos']); 624 forces a twist first.

public int pos { get; set; }

Property Value

int

Operators

implicit operator State(NativeRandomState)

Converts the legacy RandomState state (NumPy's ('MT19937', key, pos, has_gauss, gauss) tuple), which NumPy's MT19937.state setter also accepts.

public static implicit operator MT19937.State(NativeRandomState legacy)

Parameters

legacy NativeRandomState

The legacy state.

Returns

MT19937.State

The MT19937 part of it (the Gaussian cache belongs to RandomState, not the bit generator).

Exceptions

ValueError

The tuple is not an MT19937 state (state is not a legacy MT19937 state).