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 gather_index_count(&self, axis: usize) -> usize
pub fn gather_index_count(&self, axis: usize) -> usize
How many positions a gather/scatter along axis takes, when self is
the shape of the INDEX operand.
Gather’s output rank is data_rank - 1 + index_rank, so an index may be
either:
- rank >
axis— the usual case, where the index carries a dimension at the gather axis and that dimension is the count; or - a flat list (typically rank 1) that has no dimension at
axisand whose whole extent IS the count.
Every backend previously wrote idx_shape.dim(axis) here, which panics
with “Shape::dim(1) out of bounds for rank 1” on the second form — so a
rank-1 gather built a correct forward graph and then blew up the moment
it needed a backward pass. Sharing the rule keeps the five backends that
need it from disagreeing about it.
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>,
impl Eq for Shape
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,
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.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> ⓘ
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> ⓘ
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