pub struct Shape(pub Vec<usize>);Expand description
Newtype around a dimension vector that carries shape utilities.
Tuple Fields§
§0: Vec<usize>Implementations§
Source§impl Shape
impl Shape
Sourcepub fn new(dims: impl IntoIterator<Item = usize>) -> Self
pub fn new(dims: impl IntoIterator<Item = usize>) -> Self
Construct from any iterator of usize.
Sourcepub fn reshape(
&self,
new_dims: impl IntoIterator<Item = usize>,
) -> Result<Shape>
pub fn reshape( &self, new_dims: impl IntoIterator<Item = usize>, ) -> Result<Shape>
Reshape — ensures the total numel is unchanged.
Sourcepub fn broadcast_with(&self, other: &Shape) -> Result<Shape>
pub fn broadcast_with(&self, other: &Shape) -> Result<Shape>
Compute the broadcast output shape of self and other (NumPy rules).
Sourcepub fn expand_dims(&self, axis: usize) -> Result<Shape>
pub fn expand_dims(&self, axis: usize) -> Result<Shape>
Insert a new axis of size 1 at axis (like np.expand_dims).
Sourcepub fn flat_index(&self, idx: &[usize]) -> Result<usize>
pub fn flat_index(&self, idx: &[usize]) -> Result<usize>
Contiguous byte offset for a multi-index into row-major storage.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Shape
impl<'de> Deserialize<'de> for Shape
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more