Trait dfdx::tensor_ops::Roll
source · pub trait Roll: HasShape + HasErr {
// Required method
fn try_roll<Ax: Axes<Array = [isize; 1]>>(
self,
amount: usize
) -> Result<Self, Self::Err>
where Self::Shape: HasAxes<Ax>;
// Provided method
fn roll<Ax: Axes<Array = [isize; 1]>>(self, amount: usize) -> Self
where Self::Shape: HasAxes<Ax> { ... }
}
Expand description
Shifts data along an axis by a specified amount.
let t = dev.tensor([1.0, 2.0, 3.0, 4.0]);
let r = t.roll::<Axis<0>>(1);
assert_eq!(r.array(), [4.0, 1.0, 2.0, 3.0]);
Won’t compile if you try to roll an axis that doesn’t exist:
ⓘ
let t = dev.tensor([1.0, 2.0, 3.0, 4.0]);
let r = t.roll::<Axis<3>>(1);
assert_eq!(r.array(), [4.0, 1.0, 2.0, 3.0]);