Skip to content
fn

repeat

→Tensor
repeat(tensor: Tensor | list[Tensor], pattern: str, axes_lengths: int = {})

Implementing kernel

C++ engine symbols that back this Python API.

Repeat tensor along new or existing axes via an einops pattern.

Provides a single notation for both tiling along existing axes and broadcasting into entirely new axes. The pattern's right-hand side enumerates the desired output axes; any axis appearing on the right but not on the left is introduced and must be given an explicit length through **axes_lengths, or written as a number.

Parameters

tensorTensor or list of Tensor
Input tensor to repeat. A list of equally shaped tensors is stacked along a new leading axis first, so the pattern names it.
patternstr
Einops pattern such as "b h w -> b h w c" (new axis c) or "h w -> (h 2) w" (each row twice).
**axes_lengthsint= {}
Lengths for every new named axis, and checks for axes the input already fixes.

Returns

Tensor

The repeated tensor.

Raises

lucid._C.engine.InvalidArgument
The pattern is malformed, drops an axis, or introduces a named axis without a length.
lucid._C.engine.ShapeMismatch
The input's shape does not fit the pattern or the keyword lengths.

Notes

For an axis cc of size CC introduced via repeat,

ybhwc=xbhw,c=1,…,C.y_{b h w c} = x_{b h w}, \quad c = 1, \ldots, C.

No data is materialised until reading — internally the new axis is expressed as a broadcast / stride manipulation when possible.

Examples

>>> import lucid
>>> x = lucid.randn(2, 3, 4)
>>> lucid.einops.repeat(x, "b h w -> b h w c", c=5).shape
(2, 3, 4, 5)
>>> lucid.einops.repeat(lucid.tensor([[1.0, 2.0]]), "h w -> (h 2) w")
tensor([[1., 2.], [1., 2.]])