pub struct Shape { /* private fields */ }Expand description
Shape metadata for an N-dimensional tensor.
Stores dimension sizes and precomputed row-major strides. Strides follow
the standard row-major formula: strides[n-1] = 1 and
strides[i] = strides[i+1] * dims[i+1] for preceding dimensions.
§Examples
use grafos_tensor::Shape;
let s = Shape::new(&[2, 3, 4]);
assert_eq!(s.dims(), &[2, 3, 4]);
assert_eq!(s.strides(), &[12, 4, 1]);
assert_eq!(s.numel(), 24);
assert_eq!(s.ndim(), 3);Implementations§
Source§impl Shape
impl Shape
Sourcepub fn new(dims: &[usize]) -> Self
pub fn new(dims: &[usize]) -> Self
Create a new shape from dimension sizes.
Strides are computed in row-major (C) order: the last dimension has stride 1, and each preceding dimension’s stride is the product of all following dimension sizes.
An empty dims slice creates a scalar (0-D) shape with numel() == 1.
§Examples
use grafos_tensor::Shape;
let s = Shape::new(&[2, 3]);
assert_eq!(s.strides(), &[3, 1]);
let scalar = Shape::new(&[]);
assert_eq!(scalar.numel(), 1);Trait Implementations§
impl Eq for Shape
impl StructuralPartialEq for Shape
Auto Trait Implementations§
impl Freeze for Shape
impl RefUnwindSafe for Shape
impl Send for Shape
impl Sync for Shape
impl Unpin for Shape
impl UnwindSafe for Shape
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more