fn

roll

Tensor
roll(input: Tensor, shifts: int | Sequence[int], dims: Sequence[int])
source

Cyclically shift the elements of input along dims.

Elements that would shift past the boundary wrap around to the other side. Multiple axes may be rolled simultaneously by passing a list of shifts and a matching list of dims.

Parameters

inputTensor
Source tensor.
shiftsint or sequence of int
Number of positions to shift (positive = forward).
dimssequence of int
Axes along which to roll.

Returns

Tensor

Tensor of the same shape with elements cyclically shifted.

Notes

Roll is its own inverse with the opposite sign of shifts. Used extensively in FFT-based convolution to align spectra.

Examples

>>> import lucid
>>> x = lucid.arange(5)
>>> lucid.roll(x, shifts=2, dims=[0])
Tensor([3, 4, 0, 1, 2])