full_like(input: Tensor, fill_value: _complex, dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: _bool = False)Implementing kernel
C++ engine symbols that back this Python API.Return a constant-filled tensor with the same shape, dtype, and device as input.
Every element of the output equals fill_value:
where and .
This is the shape-aware generalisation of full.
Parameters
inputTensorReference tensor. Shape, dtype, and device are inherited unless
overridden by the keyword arguments.
fill_valuebool, int, float or complexScalar constant to broadcast across all elements, stored exactly
in the result's dtype as
full stores it.dtypelucid.dtypeOverride the data type. The value is filled in this dtype
directly, not filled in
t.dtype and cast — so
full_like(int_tensor, 2.5, dtype=lucid.float32) holds 2.5.devicestr or lucid.deviceOverride the device.
requires_gradboolIf
True, the constant tensor is a leaf recorded by autograd.
Default: False.Returns
TensorConstant tensor shaped like input.
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)