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
tensorTensorInput tensor to repeat.
patternstrEinops 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
TensorThe repeated tensor.
Raises
lucid._C.engine.InvalidArgumentThe pattern is malformed, drops an axis, or introduces a named
axis without a length.
lucid._C.engine.ShapeMismatchThe input's shape does not fit the pattern or the keyword lengths.
Notes
For an axis of size introduced via repeat,
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.]])