pub struct Shape { /* private fields */ }Expand description
Shape of an n-dimensional array.
Represented as a vector of dimensions. An empty vector represents a scalar.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn new(dims: Vec<usize>) -> Self
pub fn new(dims: Vec<usize>) -> Self
Create a new shape from dimensions.
§Examples
let shape = Shape::new(vec![2, 3, 4]);
assert_eq!(shape.ndim(), 3);
assert_eq!(shape.size(), 24);Sourcepub fn get(&self, index: usize) -> Option<usize>
pub fn get(&self, index: usize) -> Option<usize>
Get a specific dimension, or None if out of bounds.
Sourcepub fn default_strides(&self) -> Vec<usize>
pub fn default_strides(&self) -> Vec<usize>
Compute default row-major (C-order) strides for this shape.
§Examples
let shape = Shape::new(vec![2, 3, 4]);
let strides = shape.default_strides();
assert_eq!(strides, vec![12, 4, 1]);Sourcepub fn broadcast_with(&self, other: &Shape) -> Option<Shape>
pub fn broadcast_with(&self, other: &Shape) -> Option<Shape>
Check if two shapes are broadcast-compatible and return the result shape.
Following NumPy broadcasting rules: dimensions are compatible if they are equal or one of them is 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.