fn
roll
→Tensorroll(input: Tensor, shifts: int | Sequence[int], dims: Sequence[int])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
inputTensorSource tensor.
shiftsint or sequence of intNumber of positions to shift (positive = forward).
dimssequence of intAxes along which to roll.
Returns
TensorTensor 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])