fn

repeat

Tensor
repeat(tensor: Tensor, pattern: str, axes_lengths: int = {})
source

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.

Parameters

tensorTensor
Input tensor to repeat.
patternstr
Einops pattern such as "b h w -> b h w c" (new axis c).
**axes_lengthsint= {}
Sizes for every new axis introduced by the pattern.

Returns

Tensor

The repeated tensor.

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)