Mojo struct
Dim
@register_passable(trivial)
struct Dim
A static or dynamic dimension modeled with an optional integer.
This class is meant to represent an optional static dimension. When a value is present, the dimension has that static value. When a value is not present, the dimension is dynamic.
Implemented traits
AnyType,
Boolable,
CeilDivable,
Copyable,
Defaultable,
EqualityComparable,
ImplicitlyBoolable,
ImplicitlyCopyable,
Indexer,
Intable,
Movable,
Stringable,
UnknownDestructibility,
Writable
Aliases
__copyinit__is_trivial
alias __copyinit__is_trivial = Int.__copyinit__is_trivial
__del__is_trivial
alias __del__is_trivial = Int.__del__is_trivial
__moveinit__is_trivial
alias __moveinit__is_trivial = Int.__moveinit__is_trivial
Methods
__init__
@implicit
__init__[I: Intable](value: I) -> Self
Creates a statically-known dimension.
Parameters:
- I (Intable): The Intable type.
Args:
- value (I): The static dimension value.
@implicit
__init__[I: Indexer](value: I) -> Self
Creates a statically-known dimension.
Parameters:
- I (Indexer): A type that can be used as an index.
Args:
- value (I): The static dimension value.
__init__(value: index) -> Self
Creates a statically-known dimension.
Args:
- value (index): The static dimension value.
@implicit
__init__(value: Int) -> Self
Creates a statically-known dimension.
Args:
- value (Int): The static dimension value.
__init__() -> Self
Creates a dynamic dimension with no static value.
__bool__
__bool__(self) -> Bool
Returns True if the dimension has a static value.
Returns:
Bool: Whether the dimension has a static value.
__eq__
__eq__(self, rhs: Self) -> Bool
Compares two dimensions for equality.
Args:
- rhs (Self): The other dimension.
Returns:
Bool: True if the dimensions are the same.
__mul__
__mul__(self, rhs: Self) -> Self
Multiplies two dimensions.
If either are unknown, the result is unknown as well.
Args:
- rhs (Self): The other dimension.
Returns:
Self: The product of the two dimensions.
__floordiv__
__floordiv__(self, rhs: Self) -> Self
Divide by the given dimension and round towards negative infinity.
If either are unknown, the result is unknown as well.
Args:
- rhs (Self): The divisor dimension.
Returns:
Self: The floor division of the two dimensions.
__rfloordiv__
__rfloordiv__(self, rhs: Self) -> Self
Divide the given argument by self and round towards negative infinity.
If either are unknown, the result is unknown as well.
Args:
- rhs (Self): The dimension to divide by this Dim.
Returns:
Self: The floor of the argument divided by self.
__imul__
__imul__(mut self, rhs: Self)
Inplace multiplies two dimensions.
If either are unknown, the result is unknown as well.
Args:
- rhs (Self): The other dimension.
__as_bool__
__as_bool__(self) -> Bool
Returns True if the dimension has a static value.
Returns:
Bool: Whether the dimension has a static value.
has_value
has_value(self) -> Bool
Returns True if the dimension has a static value.
Returns:
Bool: Whether the dimension has a static value.
is_dynamic
is_dynamic(self) -> Bool
Returns True if the dimension has a dynamic value.
Returns:
Bool: Whether the dimension is dynamic.
get
is_multiple
is_multiple[alignment: Int](self) -> Bool
Checks if the dimension is aligned.
Parameters:
- alignment (Int): The alignment requirement.
Returns:
Bool: Whether the dimension is aligned.
__index__
__index__(self) -> index
Convert to index.
Returns:
index: The corresponding __mlir_type.index value.
__ceildiv__
__ceildiv__(self, rhs: Self) -> Self
Return the rounded-up result of dividing self by denominator dimension.
If either are unknown, the result is unknown as well.
Args:
- rhs (Self): The denominator dimension.
Returns:
Self: The rounded-up result of dividing self by denominator dimension.
__int__
__str__
__str__(self) -> String
Converts the Dim to a String. If the value is unknown, then the string "?" is returned.
Returns:
String: The string representation of the type.
write_to
write_to(self, mut writer: T)
Formats this DimList to the provided Writer.
Args:
- writer (T): The object to write to.
or_else
or_else(self, default: Int) -> Int
Return the underlying value contained in the Optional or a default value if the Optional's underlying value is not present.
Args:
- default (Int): The new value to use if no value was present.
Returns:
Int: The underlying value contained in the Optional or a default value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
