Skip to main content

Mojo struct

ShapeElement

A single dimension of a possibly-dynamic shape.

A shape element can be static or dynamic. If dynamic, it can be named or unnamed. Named dynamic shape elements must match across all inputs of a model.

Implemented traits

AnyType, CollectionElement, Copyable, EqualityComparable, Movable

Methods

__init__

__init__(out self, static: Int)

Create a static shape element with the given static dimension value.

Args:

  • static (Int): The static size of the dimension.

__init__(out self, static: SIMD[int64, 1])

Create a static shape element with the given static dimension value.

Args:

  • static (SIMD[int64, 1]): The static size of the dimension.

__init__(out self, unnamed: None)

Create an unnamed dynamic shape element.

Args:

  • unnamed (None): None.

__init__(out self, unnamed: NoneType)

Create an unnamed dynamic shape element.

Args:

  • unnamed (NoneType): None.

__init__(out self, owned name: String)

Create a dynamic shape element with the given name.

Args:

  • name (String): The name of the dimension, which must be non-empty, consist only of alphanumeric characters and underscores, and must not begin with a digit.

__init__(out self, name: StringRef)

Create a dynamic shape element with the given name.

Args:

  • name (StringRef): The name of the dimension, which must be non-empty, consist only of alphanumeric characters and underscores, and must not begin with a digit.

__init__(out self, name: StringLiteral)

Create a dynamic shape element with the given name.

Args:

  • name (StringLiteral): The name of the dimension, which must be non-empty, consist only of alphanumeric characters and underscores, and must not begin with a digit.

__copyinit__

__copyinit__(out self, other: Self)

Create a copy of another ShapeElement.

Args:

  • other (Self): The ShapeElement to copy from.

__moveinit__

__moveinit__(out self, owned other: Self)

Initialize from another owned ShapeElement.

Args:

  • other (Self): The ShapeElement to copy from.

__eq__

__eq__(self, other: Self) -> Bool

Determine if this shape element is equal to another.

Note that this is structural, not necessarily semantic -- two unnamed dynamic shape elements compare as equal, even though in a model such shape elements are not necessarily required to be equal.

Returns: True if shape elements are equal; False otherwise.

Args:

  • other (Self): ShapeElement to compare to.

__ne__

__ne__(self, other: Self) -> Bool

Determine if this shape element is unequal to another.

Note that this is structural, not necessarily semantic -- two unnamed dynamic shape elements compare as equal, even though in a model such shape elements are not necessarily required to be equal.

Returns: True if shape elements are unequal; False otherwise.

Args:

  • other (Self): ShapeElement to compare to.

is_static

is_static(self) -> Bool

Whether this shape element is static.

Returns: True if this shape element is static; False otherwise.

is_dynamic

is_dynamic(self) -> Bool

Whether this shape element is a dynamic dimension.

Returns:

True if this shape element is a dynamic dimension; False otherwise.

is_unnamed_dynamic

is_unnamed_dynamic(self) -> Bool

Whether this shape element is an unnamed dynamic dimension.

Returns:

True if this shape element is an unnamed dynamic dimension; False otherwise.

is_named_dynamic

is_named_dynamic(self) -> Bool

Whether this shape element is a named dynamic dimension.

Returns:

True if this shape element is a named dynamic dimension; False otherwise.

static_value

static_value(self) -> SIMD[int64, 1]

Return size of this static shape element.

Returns:

Size of this static shape element, or 0 if not a static shape element.

name

name(self) -> String

Return name of this named dynamic shape element.

Returns:

Name of this named dynamic shape element, or empty string if not a named dynamic shape element.