Mojo struct
StaticTuple
struct StaticTuple[element_type: ImplicitlyCopyable & ImplicitlyDestructible & RegisterPassable, size: Int]
A statically sized tuple type which contains elements of homogeneous types.
Parameters
- element_type (
ImplicitlyCopyable&ImplicitlyDestructible&RegisterPassable): The type of the elements in the tuple. - size (
Int): The size of the tuple.
Implemented traits
AnyType,
Copyable,
Defaultable,
DevicePassable,
ImplicitlyCopyable,
ImplicitlyDestructible,
Movable,
RegisterPassable,
Sized,
TrivialRegisterPassable
comptime members
device_type
comptime device_type = StaticTuple[element_type, size]
The device-side type for this StaticTuple.
Methods
__init__
__init__() -> Self
Constructs an empty (undefined) tuple.
__init__(*, mlir_value: __mlir_type.`!pop.array<#lit.struct.extract<:!lit.struct<_std::_builtin::_int::_Int> size, "_mlir_value">, :trait<_std::_builtin::_value::_ImplicitlyCopyable, _std::_builtin::_anytype::_ImplicitlyDestructible, _std::_builtin::_value::_RegisterPassable> element_type>`) -> Self
Constructs from an array type.
Args:
- mlir_value (
__mlir_type.`!pop.array<#lit.struct.extract<:!lit.struct<_std::_builtin::_int::_Int> size, "_mlir_value">, :trait<_std::_builtin::_value::_ImplicitlyCopyable, _std::_builtin::_anytype::_ImplicitlyDestructible, _std::_builtin::_value::_RegisterPassable> element_type>`): Underlying MLIR array type.
__init__(*, fill: element_type) -> Self
Constructs a static tuple given a fill value.
Args:
- fill (
element_type): The value to fill the tuple with.
__init__(*elems: element_type) -> Self
Constructs a static tuple given a set of arguments.
Args:
- *elems (
element_type): The element types.
__init__[*values: element_type]() -> Self
Creates a tuple constant using the specified values.
Parameters:
- *values (
element_type): The list of values.
__init__(values: VariadicList[element_type, False]) -> Self
Creates a tuple constant using the specified values.
Args:
- values (
VariadicList): The list of values.
__getitem__
__getitem__[I: Indexer, //](self, idx: I) -> element_type
Returns the value of the tuple at the given dynamic index.
Parameters:
- I (
Indexer): A type that can be used as an index.
Args:
- idx (
I): The index into the tuple.
Returns:
element_type: The value at the specified position.
__setitem__
__setitem__[I: Indexer, //](mut self, idx: I, val: element_type)
Stores a single value into the tuple at the specified dynamic index.
Parameters:
- I (
Indexer): A type that can be used as an index.
Args:
- idx (
I): The index into the tuple. - val (
element_type): The value to store.
__lt__
__lt__[_E: Comparable & TrivialRegisterPassable, //](self: StaticTuple[_E, size], other: StaticTuple[_E, size]) -> Bool
Returns True if self is lexicographically less than other.
Parameters:
- _E (
Comparable&TrivialRegisterPassable): The element type, must beComparableandTrivialRegisterPassable.
Args:
- other (
StaticTuple): The tuple to compare with.
Returns:
Bool: True if self is lexicographically less than other.
__le__
__le__[_E: Comparable & TrivialRegisterPassable, //](self: StaticTuple[_E, size], other: StaticTuple[_E, size]) -> Bool
Returns True if self is lexicographically less than or equal to other.
Parameters:
- _E (
Comparable&TrivialRegisterPassable): The element type, must beComparableandTrivialRegisterPassable.
Args:
- other (
StaticTuple): The tuple to compare with.
Returns:
Bool: True if self is lexicographically less than or equal to other.
__eq__
__eq__[_E: Equatable & TrivialRegisterPassable, //](self: StaticTuple[_E, size], other: StaticTuple[_E, size]) -> Bool
Returns True if all elements are equal.
Parameters:
- _E (
Equatable&TrivialRegisterPassable): The element type, must beEquatableandTrivialRegisterPassable.
Args:
- other (
StaticTuple): The tuple to compare with.
Returns:
Bool: True if all corresponding elements are equal.
__ne__
__ne__[_E: Equatable & TrivialRegisterPassable, //](self: StaticTuple[_E, size], other: StaticTuple[_E, size]) -> Bool
Returns True if any element differs.
Parameters:
- _E (
Equatable&TrivialRegisterPassable): The element type, must beEquatableandTrivialRegisterPassable.
Args:
- other (
StaticTuple): The tuple to compare with.
Returns:
Bool: True if any corresponding elements differ.
__gt__
__gt__[_E: Comparable & TrivialRegisterPassable, //](self: StaticTuple[_E, size], other: StaticTuple[_E, size]) -> Bool
Returns True if self is lexicographically greater than other.
Parameters:
- _E (
Comparable&TrivialRegisterPassable): The element type, must beComparableandTrivialRegisterPassable.
Args:
- other (
StaticTuple): The tuple to compare with.
Returns:
Bool: True if self is lexicographically greater than other.
__ge__
__ge__[_E: Comparable & TrivialRegisterPassable, //](self: StaticTuple[_E, size], other: StaticTuple[_E, size]) -> Bool
Returns True if self is lexicographically greater than or equal to other.
Parameters:
- _E (
Comparable&TrivialRegisterPassable): The element type, must beComparableandTrivialRegisterPassable.
Args:
- other (
StaticTuple): The tuple to compare with.
Returns:
Bool: True if self is lexicographically greater than or equal to
other.
get_type_name
static get_type_name() -> String
Get the human-readable type name for this StaticTuple.
Returns:
String: A string representation of the type, e.g. "StaticTuple[Int, 3]".
__len__
__len__(self) -> Int
Returns the length of the array. This is a known constant value.
Returns:
Int: The size of the list.
get
get[index: Int](self) -> element_type
Returns the value of the tuple at the given index.
Parameters:
- index (
Int): The index into the tuple.
Returns:
element_type: The value at the specified position.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!