Skip to main content

roll

Function roll 

Source
pub fn roll<B: Backend, T: Element>(
    x: &Array<B, T>,
    shift: i64,
    axis: i64,
) -> Array<B, T>
Expand description

x with the elements along axis moved by a static shift toward higher indices, wrapping around (jnp.roll(x, shift, axis)): element i goes to (i + shift) mod n. As in JAX, it is two slices and a concatenation.

§Examples

use ruxla_core::{Array, Native, jnp};

let x = Array::<Native, i32>::from_slice(&[0, 1, 2, 3, 4], [5]);
assert_eq!(jnp::roll(&x, 2, 0).to_vec(), [3, 4, 0, 1, 2]);
assert_eq!(jnp::roll(&x, -1, 0).to_vec(), [1, 2, 3, 4, 0]);

§Panics

Panics if axis is out of range.