Generator
GeneratorGenerator(seed: int | DeviceLike = 0, device: DeviceLike = None)A Philox-4×32 random stream of its own.
Pass one as generator= to a random op to draw from it instead of the
default stream that lucid.manual_seed controls; draws through it
leave the default stream where it was.
Parameters
seedint or str or lucid.device= 0Generator("cpu")), it is read as device and the key
defaults to 0.devicestr or lucid.device= Nonedevice. Defaults to device("cpu").Raises
TypeErrorseed is not an integer or device specifier.ValueErrorseed is out of the 64-bit range or device names no
supported device.Notes
The constructor accepts both Generator(seed) and the reference's
Generator(device=...) / Generator("cpu"). seed reseeds
from entropy, as the reference's does; initial_seed reads the
key.
Examples
>>> import lucid
>>> g = lucid.Generator().manual_seed(7)
>>> g.initial_seed()
7
>>> a = lucid.rand(3, generator=g)
>>> state = g.get_state()
>>> b = lucid.rand(3, generator=g)
>>> c = lucid.rand(3, generator=g.set_state(state))
>>> bool((b == c).all())
TrueUsed by 1
- lucid._factories.random
Constructors
1Properties
1Attributes
1Instance methods
5The stream's position, [key, counter], as an int64 tensor.
Returns
TensorShape (2,); set_state returns the stream to it.
The key this stream was last seeded with.
Returns
intThe key, in .
Set the key to seed and rewind the stream to its start.
Parameters
seedintReturns
GeneratorThis generator, so a call can be chained.
Reseed the stream from the OS entropy source and return the new key.
Returns
intThe key, in ; manual_seed with it
replays the stream from here.