roll(input: Tensor, shifts: _int | Sequence[_int], dims: _int | Sequence[_int] | None = ...)Implementing kernel
C++ engine symbols that back this Python API.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. Without dims the elements
roll in their flattened order and the shape is put back.
Parameters
inputTensorSource tensor.
shiftsint or sequence of intNumber of positions to shift (positive = forward). A single int
when
dims is None; otherwise one per entry of dims.dimsint, sequence of int, or None= ...Axes along which to roll.
None (default) rolls the flattened
tensor.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], dtype=lucid.int64)
>>> lucid.roll(lucid.arange(6).reshape(2, 3), 1)
tensor([[5, 0, 1], [2, 3, 4]], dtype=lucid.int64)