fn

repeat_interleave

Tensor
repeat_interleave(x: Tensor, repeats: _int, dim: _int | None = None)
source

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

xTensor
Source tensor.
repeatsint
Number of repeats per element.
dimint= None
Axis along which to interleave. None flattens first.

Returns

Tensor

Newly-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])