fn

full

Tensor
full(size: _int | list[_int] | tuple[_int, ...], fill_value: _float, dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: _bool = False)
source

Return a tensor filled with a constant scalar value.

Every element of the output equals fill_value:

Fi1,,in=c  (i1,,in)k[0,sk)F_{i_1, \ldots, i_n} = c \quad \forall\; (i_1, \ldots, i_n) \in \prod_k [0, s_k)

where cc is fill_value. This is a generalisation of zeros (c=0c = 0) and ones (c=1c = 1) to an arbitrary constant.

Parameters

sizeint or list[int] or tuple[int, ...]
Shape of the output tensor. Unlike the *size varargs of zeros / ones, this is a single positional argument, so multi-dimensional shapes must be passed as a list or tuple: full((2, 3), 7.0).
fill_valuefloat
The scalar constant to broadcast across all elements.
dtypelucid.dtype
Scalar data type. If None, inferred from fill_value (integers → int64, floats → the global default float dtype).
devicestr or lucid.device
Target device — "cpu" or "metal".
requires_gradbool
If True, downstream operations are tracked by autograd. Default: False.

Returns

Tensor

Constant tensor of shape size filled with fill_value.

Notes

Every output element is assigned fill_value exactly — there is no broadcasting needed once the scalar reaches the engine. When dtype is omitted, the type is inferred from the Python type of fill_value: int literals promote to int64 and float literals to the global default floating dtype (lucid.float32 by default). If fill_value is a 0-d tensor (Tensor of shape ()), its scalar value is extracted via Tensor.item and broadcast across the full tensor; element-wise broadcasting from a larger tensor is not supported here (use lucid.broadcast_to instead).

Examples

>>> import lucid
>>> lucid.full((2, 3), 3.14).shape
(2, 3)
>>> lucid.full(4, -1.0).tolist()
[-1.0, -1.0, -1.0, -1.0]
Mask of a fixed value (e.g. $-\infty$ for attention masking):
>>> mask = lucid.full((4, 4), float("-inf"))