fn
repeat_interleave
→Tensorrepeat_interleave(x: Tensor, repeats: _int, dim: _int | None = None)Repeat each element of x repeats times along dim.
The opposite ordering of repeat: instead of replicating the
whole block, each individual element (or sub-slice) is replicated
contiguously before moving on.
Parameters
xTensorSource tensor.
repeatsintNumber of repeats per element.
dimint= NoneAxis along which to interleave.
None flattens first.Returns
TensorNewly-allocated tensor with size repeats * x.size(dim) along
dim.
Notes
Useful for upsampling tensors by integer factors without interpolation (nearest-neighbour upsample = interleave + reshape).
Examples
>>> import lucid
>>> x = lucid.tensor([1, 2, 3])
>>> lucid.repeat_interleave(x, 2, dim=0)
Tensor([1, 1, 2, 2, 3, 3])