pub struct Shape { /* private fields */ }Expand description
Dimension extents for a tensor (e.g. [batch, rows, cols]).
Stored inline (stack-allocated) for rank ≤ 8, heap-allocated otherwise.
This struct is Send and Sync because all its components (usize and smallvec::SmallVec) are Send and Sync.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn numel(&self) -> usize
pub fn numel(&self) -> usize
Returns the total number of elements (product of all dimensions).
Returns 1 for a scalar (rank-0) shape.
Sourcepub fn row_major_strides(&self) -> Strides
pub fn row_major_strides(&self) -> Strides
Computes row-major (C-order) strides for this shape.
For a shape [d0, d1, d2, …, dn] the strides are
[d1*d2*…*dn, d2*…*dn, …, dn, 1].
Broadcasting dimensions (size == 1) receive stride 0 so that their
element is reused without copying.
Sourcepub fn broadcast_compatible(&self, other: &Self) -> bool
pub fn broadcast_compatible(&self, other: &Self) -> bool
Returns true if the two shapes are broadcast-compatible.
Shapes are broadcast-compatible if, after right-aligning them, every pair of dimensions is either equal or one of them is 1.
Sourcepub fn broadcast_output(&self, other: &Self) -> Option<Self>
pub fn broadcast_output(&self, other: &Self) -> Option<Self>
Returns the output shape after broadcasting two shapes together.
§Errors
Returns None if the shapes are not broadcast-compatible.
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 UnsafeUnpin 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
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
key and return true if they are equal.