fn
full_like
→Tensorfull_like(t: Tensor, fill_value: _float, dtype: DTypeLike = None, device: DeviceLike = None)Return a constant-filled tensor with the same shape, dtype, and device as t.
Every element of the output equals fill_value:
where and .
This is the shape-aware generalisation of full.
Parameters
tTensorReference tensor. Shape, dtype, and device are inherited unless
overridden by the keyword arguments.
fill_valuefloatScalar constant to broadcast across all elements.
dtypelucid.dtypeOverride the data type. When specified, the result is cast via
astype after allocation, so the output dtype matches the
override rather than t.dtype.devicestr or lucid.deviceOverride the device. When specified, the result is moved via
to after allocation.Returns
TensorConstant tensor shaped like t.
Notes
A canonical application is initialising the attention bias mask before selectively unmasking positions. Starting from on a tensor shaped like the attention weight matrix ensures that masked positions become zero after softmax:
Examples
>>> import lucid
>>> scores = lucid.randn(4, 8)
>>> mask = lucid.full_like(scores, float("-inf"))
>>> mask.shape
(4, 8)
Constant padding value:
>>> x = lucid.randn(2, 3)
>>> padded = lucid.full_like(x, -1.0)