flopscope.numpy.random.Generator
flopscope.numpy.random.Generator[flopscope source]
numpy ``Generator`` subclass with FLOP-counted sampler methods.
numpy Generator subclass with FLOP-counted sampler methods.
Each sampler method (standard_normal, normal, uniform,
integers, choice, shuffle, permutation, bytes, ...)
deducts FLOPs from the active BudgetContext and returns
FlopscopeArray. Free attribute access (bit_generator, spawn)
is allowed; anything else raises UnsupportedFunctionError.
Construct via flopscope.flops.random.default_rng (canonical) or by
passing a BitGenerator directly: Generator(flops.random.PCG64(42)).
See also
- we.fnp.random.default_rng canonical constructor.
Examples
>>> import flopscope.numpy as fnp
>>> from flopscope import BudgetContext
>>> rng = fnp.random.default_rng(42)
>>> with BudgetContext(flop_budget=10**6):
... x = rng.standard_normal((10,))
>>> type(x).__name__
'FlopscopeArray'Pickle / copy round-trips preserve counting:
>>> import pickle
>>> revived = pickle.loads(pickle.dumps(rng))
>>> isinstance(revived, type(rng))
True