Mojo struct
RuntimeInt
@register_passable(trivial)
struct RuntimeInt[dtype: DType = DType.int]
Runtime index value with configurable precision.
Parameters
- dtype (
DType): The data type for the runtime integer value. Defaults toDType.int.
Implemented traits
AnyType,
CoordLike,
Copyable,
Defaultable,
ImplicitlyCopyable,
ImplicitlyDestructible,
Movable,
RegisterPassable,
TrivialRegisterPassable,
Writable
comptime members
__copy_ctor_is_trivial
comptime __copy_ctor_is_trivial = True
__del__is_trivial
comptime __del__is_trivial = True
__move_ctor_is_trivial
comptime __move_ctor_is_trivial = True
DTYPE
comptime DTYPE = dtype
The data type for the runtime integer value.
is_static_value
comptime is_static_value = False
True if the value is known at compile time.
is_tuple
comptime is_tuple = False
True if this is a tuple type (Coord), False for scalar values.
is_value
comptime is_value = True
True if this is a scalar value, False for tuple types.
static_value
comptime static_value = -1
Always -1 for runtime values (not statically known).
VariadicType
comptime VariadicType = RuntimeInt[dtype]
The variadic element types (Self for scalar types).
Methods
__init__
__init__() -> Self
Initialize a runtime integer with value 0.
__init__(value: Scalar[dtype]) -> Self
Initialize a runtime integer with the given value.
Args:
- value (
Scalar): The scalar value to store.
__len__
__repr__
__repr__(self) -> String
Get the string representation of this runtime integer.
Returns:
String: A string in the format "RuntimeInt(value)".
write_to
write_to(self, mut writer: T)
Write this runtime integer to a writer.
Args:
- writer (
T): The writer to write to.
write_repr_to
write_repr_to(self, mut writer: T)
Write the repr of this runtime integer to a writer.
Args:
- writer (
T): The writer to write to.
product
product(self) -> Int
Calculate the product (returns the value for scalar types).
Returns:
Int: The integer value.
sum
sum(self) -> Int
Calculate the sum (returns the value for scalar types).
Returns:
Int: The integer value.
value
tuple
tuple(var self) -> Coord[RuntimeInt[dtype].VariadicType]
Get as a tuple (not valid for RuntimeInt).
Returns:
Coord: Never returns; aborts at compile time.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!