fn
empty_like
→Tensorempty_like(t: Tensor, dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: _bool = False)Return an uninitialised tensor with the same shape, dtype, and device as t.
Allocates backing memory matching t's metadata but performs no
initialisation write. Reading elements before overwriting them is
undefined behaviour. The typical use is to pre-allocate an output
buffer for an in-place kernel call:
Parameters
tTensorReference tensor whose
shape, dtype, and device are
inherited by the output.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
TensorUninitialised tensor shaped like t.
Notes
Skipping the zero-fill write is only a win when the allocation is
large and will be fully overwritten before any read. For small
tensors the branch-prediction and cache effects of the explicit
initialisation kernel are negligible; prefer zeros_like in those
cases for safety.
Examples
>>> import lucid
>>> x = lucid.randn(1024, 1024)
>>> buf = lucid.empty_like(x) # fast scratch space
>>> buf.shape
(1024, 1024)