fn
rand_like
→Tensorrand_like(t: Tensor, dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: _bool = False)Return a random tensor with the same shape, dtype, and device as t.
Equivalent to lucid.rand(t.shape, dtype=t.dtype, device=t.device),
but infers metadata from an existing tensor so the caller need not
repeat shape and type information.
Each element is drawn independently from
Parameters
tTensorReference tensor. Its
shape, dtype, and device are
inherited by the output unless overridden.dtypelucid.dtypeOverride the data type. Defaults to
t.dtype.devicestr or lucid.deviceOverride the device. Defaults to
t.device.requires_gradboolEnable autograd tracking. Default:
False.Returns
TensorUniform random tensor shaped like t.
Notes
The returned tensor mirrors t's shape, dtype, and
device exactly unless overridden via the corresponding keyword
arguments. Sampling follows the same dtype-default rule as
lucid.rand: only floating-point dtypes are supported. Calling
this on an integer tensor without overriding dtype raises — use
lucid.randint_like for integer noise.
Examples
>>> import lucid
>>> x = lucid.zeros(3, 4, device="metal")
>>> noise = lucid.rand_like(x)
>>> noise.shape, noise.device
((3, 4), lucid.device('metal'))