Mojo 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
,
Copyable
,
Formattable
,
ImplicitlyBoolable
,
Intable
,
Movable
,
Stringable
Methodsβ
__init__
β
__init__[type: Intable](inout self: Self, value: type)
Creates a statically-known dimension.
Parameters:
- βtype (
Intable
): The Intable type.
Args:
- βvalue (
type
): The static dimension value.
__init__(inout self: Self, value: index)
Creates a statically-known dimension.
Args:
- βvalue (
index
): The static dimension value.
__init__(inout self: Self)
Creates a dynamic dimension with no static value.
__bool__
β
__bool__(self: Self) -> Bool
Returns True if the dimension has a static value.
Returns:
Whether the dimension has a static value.
__eq__
β
__eq__(self: Self, rhs: Self) -> Bool
Compares two dimensions for equality.
Args:
- βrhs (
Self
): The other dimension.
Returns:
True if the dimensions are the same.
__ne__
β
__ne__(self: Self, rhs: Self) -> Bool
Compare two dimensions for inequality.
Args:
- βrhs (
Self
): The dimension to compare.
Returns:
True if they are not equal.
__mul__
β
__mul__(self: Self, rhs: Self) -> Self
Multiplies two dimensions.
If either are unknown, the result is unknown as well.
Args:
- βrhs (
Self
): The other dimension.
Returns:
The product of the two dimensions.
__floordiv__
β
__floordiv__(self: 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:
The floor division of the two dimensions.
__rfloordiv__
β
__rfloordiv__(self: 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:
The floor of the argument divided by self.
__imul__
β
__imul__(inout self: 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: Self) -> Bool
Returns True if the dimension has a static value.
Returns:
Whether the dimension has a static value.
has_value
β
has_value(self: Self) -> Bool
Returns True if the dimension has a static value.
Returns:
Whether the dimension has a static value.
is_dynamic
β
is_dynamic(self: Self) -> Bool
Returns True if the dimension has a dynamic value.
Returns:
Whether the dimension is dynamic.
get
β
get(self: Self) -> Int
Gets the static dimension value.
Returns:
The static dimension value.
is_multiple
β
is_multiple[alignment: Int](self: Self) -> Bool
Checks if the dimension is aligned.
Parameters:
- βalignment (
Int
): The alignment requirement.
Returns:
Whether the dimension is aligned.
__int__
β
__int__(self: Self) -> Int
Gets the static dimension value.
Returns:
The static dimension value.
__str__
β
__str__(self: Self) -> String
Converts the Dim to a String. If the value is unknown, then the string "?" is returned.
Returns:
The string representation of the type.
format_to
β
format_to(self: Self, inout writer: Formatter)
Formats this DimList to the provided formatter.
Args:
- βwriter (
Formatter
): The formatter to write to.
or_else
β
or_else(self: 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:
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!
If you'd like to share more information, please report an issue on GitHub
π What went wrong?