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) -> Shape
pub fn from_dims(dims: &[Dim], dtype: DType) -> Shape
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) -> Shape
pub fn bind(&self, bindings: &DimBinding) -> Shape
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) -> Shape
pub fn with_dtype(self, dtype: DType) -> Shape
Change dtype (for cast operations).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Shape
impl<'de> Deserialize<'de> for Shape
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Shape, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Shape, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Shape
impl Serialize for Shape
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. 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
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more