pub enum ShapeTuple {
Leaf(usize),
Nested(Vec<ShapeTuple>),
}Expand description
Hierarchical shape tuple (plan #38). Borrowed from MAX’s
layout/int_tuple.mojo: shapes nest, so a ((B, S), (H, D))
expression captures the “outer batch+seq, inner heads+head_dim”
structure of a tiled layout. Useful for kernels that want to
reason about block-tiled sweeps without re-deriving the
implied stride math each time.
Stays alongside the existing flat crate::Shape (which is
what every op carries today). New code that benefits from
hierarchy uses ShapeTuple; we don’t migrate Shape because
the entire codebase is built around it and the win is
concentrated in advanced layout / fusion code.
Variants§
Leaf(usize)
Single concrete dimension.
Nested(Vec<ShapeTuple>)
Ordered list of sub-tuples. Nesting is unbounded.
Implementations§
Source§impl ShapeTuple
impl ShapeTuple
Sourcepub fn nested(parts: Vec<ShapeTuple>) -> Self
pub fn nested(parts: Vec<ShapeTuple>) -> Self
Wrapping constructor for nested layouts.
Sourcepub fn flat(dims: &[usize]) -> Self
pub fn flat(dims: &[usize]) -> Self
Convenience: build a flat tuple from &[usize]. Each
element becomes a Leaf. flat(&[2, 3, 4]) is equivalent
to Nested(vec![Leaf(2), Leaf(3), Leaf(4)]).
pub fn is_leaf(&self) -> bool
Sourcepub fn rank(&self) -> usize
pub fn rank(&self) -> usize
Top-level rank. Leaves are rank 1; nested tuples are the length of the outer list.
Sourcepub fn flatten(&self) -> Vec<usize>
pub fn flatten(&self) -> Vec<usize>
Flatten into a row-major sequence of leaves. Useful when
converting to the existing Shape type.
Sourcepub fn get(&self, path: &[usize]) -> Option<&ShapeTuple>
pub fn get(&self, path: &[usize]) -> Option<&ShapeTuple>
Walk a path of indices through the hierarchy. Returns
the sub-tuple at path or None if the path goes out of
bounds at any level.
[] returns Some(self); [0] returns the first child.
Trait Implementations§
Source§impl Clone for ShapeTuple
impl Clone for ShapeTuple
Source§fn clone(&self) -> ShapeTuple
fn clone(&self) -> ShapeTuple
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ShapeTuple
impl Debug for ShapeTuple
impl Eq for ShapeTuple
Source§impl PartialEq for ShapeTuple
impl PartialEq for ShapeTuple
Source§fn eq(&self, other: &ShapeTuple) -> bool
fn eq(&self, other: &ShapeTuple) -> bool
self and other values to be equal, and is used by ==.