pub struct Shape { /* private fields */ }Expand description
Tensor shape: ordered list of dimensions + element type.
SmallVec<[Dim; 4]> avoids heap allocation for up to 4D tensors (the common case).
Implementations§
Source§impl Shape
impl Shape
Source§impl Shape
impl Shape
Sourcepub fn from_dims(dims: &[Dim], dtype: DType) -> Self
pub fn from_dims(dims: &[Dim], dtype: DType) -> Self
Create a shape with mixed static/dynamic dimensions.
pub fn rank(&self) -> usize
pub fn dtype(&self) -> DType
pub fn dims(&self) -> &[Dim]
pub fn dim(&self, i: usize) -> Dim
Sourcepub fn dynamic_symbols(&self) -> Vec<u32>
pub fn dynamic_symbols(&self) -> Vec<u32>
Set of dynamic dim symbols this shape references. Useful for “what bindings does this graph need?” queries on inputs.
Sourcepub fn bind(&self, bindings: &DimBinding) -> Self
pub fn bind(&self, bindings: &DimBinding) -> Self
Specialize the shape against a binding (symbol → static size). Unknown symbols stay Dim::Dynamic. Plan #54: the
step that takes a “compile once, run at any seq length” graph
and produces the runtime-specific concrete shape.
Sourcepub fn num_elements(&self) -> Option<usize>
pub fn num_elements(&self) -> Option<usize>
Total number of elements (only if all dims are static).
Sourcepub fn size_bytes(&self) -> Option<usize>
pub fn size_bytes(&self) -> Option<usize>
Total size in bytes (only if all dims are static).
Sourcepub fn with_dtype(self, dtype: DType) -> Self
pub fn with_dtype(self, dtype: DType) -> Self
Change dtype (for cast operations).
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
Mutably borrows from an owned value. Read more