Mojo struct
StaticIntTuple
A base struct that implements size agnostic index functions.
Parameters
- size (
Int
): The size of the tuple.
Fields
- data (
StaticTuple[Int, size]
): The underlying storage of the tuple value.
Implemented traits
AnyType
,
Comparable
,
Copyable
,
EqualityComparable
,
Formattable
,
Movable
,
Sized
,
Stringable
Methods
__init__
__init__(inout self: Self)
Constructs a static int tuple of the given size.
__init__(inout self: Self, value: index)
Constructs a sized 1 static int tuple of given the element value.
Args:
- value (
index
): The initial value.
__init__(inout self: Self, elems: Tuple[Int, Int])
Constructs a static int tuple given a tuple of integers.
Args:
- elems (
Tuple[Int, Int]
): The tuple to copy from.
__init__(inout self: Self, elems: Tuple[Int, Int, Int])
Constructs a static int tuple given a tuple of integers.
Args:
- elems (
Tuple[Int, Int, Int]
): The tuple to copy from.
__init__(inout self: Self, elems: Tuple[Int, Int, Int, Int])
Constructs a static int tuple given a tuple of integers.
Args:
- elems (
Tuple[Int, Int, Int, Int]
): The tuple to copy from.
__init__(inout self: Self, *elems: Int)
Constructs a static int tuple given a set of arguments.
Args:
- *elems (
Int
): The elements to construct the tuple.
__init__(inout self: Self, elem: Int)
Constructs a static int tuple given a set of arguments.
Args:
- elem (
Int
): The elem to splat into the tuple.
__init__(inout self: Self, *, other: Self)
Copy constructor.
Args:
- other (
Self
): The other tuple to copy from.
__init__(inout self: Self, values: VariadicList[Int])
Creates a tuple constant using the specified values.
Args:
- values (
VariadicList[Int]
): The list of values.
__getitem__
__getitem__(self: Self, idx: Int) -> Int
Gets an element from the tuple by index.
Args:
- idx (
Int
): The element index.
Returns:
The tuple element value.
__setitem__
__setitem__[index: Int](inout self: Self, val: Int)
Sets an element in the tuple at the given static index.
Parameters:
- index (
Int
): The element index.
Args:
- val (
Int
): The value to store.
__setitem__(inout self: Self, idx: Int, val: Int)
Sets an element in the tuple at the given index.
Args:
- idx (
Int
): The element index. - val (
Int
): The value to store.
__lt__
__lt__(self: Self, rhs: Self) -> Bool
Compares this tuple to another tuple using LT comparison.
A tuple is less-than another tuple if all corresponding elements of lhs is less than rhs.
Note: This is not a lexical comparison.
Args:
- rhs (
Self
): Right hand side tuple.
Returns:
The comparison result.
__le__
__le__(self: Self, rhs: Self) -> Bool
Compares this tuple to another tuple using LE comparison.
A tuple is less-or-equal than another tuple if all corresponding elements of lhs is less-or-equal than rhs.
Note: This is not a lexical comparison.
Args:
- rhs (
Self
): Right hand side tuple.
Returns:
The comparison result.
__eq__
__eq__(self: Self, rhs: Self) -> Bool
Compares this tuple to another tuple for equality.
The tuples are equal if all corresponding elements are equal.
Args:
- rhs (
Self
): The other tuple.
Returns:
The comparison result.
__ne__
__ne__(self: Self, rhs: Self) -> Bool
Compares this tuple to another tuple for non-equality.
The tuples are non-equal if at least one element of LHS isn't equal to the corresponding element from RHS.
Args:
- rhs (
Self
): The other tuple.
Returns:
The comparison result.
__gt__
__gt__(self: Self, rhs: Self) -> Bool
Compares this tuple to another tuple using GT comparison.
A tuple is greater-than than another tuple if all corresponding elements of lhs is greater-than than rhs.
Note: This is not a lexical comparison.
Args:
- rhs (
Self
): Right hand side tuple.
Returns:
The comparison result.
__ge__
__ge__(self: Self, rhs: Self) -> Bool
Compares this tuple to another tuple using GE comparison.
A tuple is greater-or-equal than another tuple if all corresponding elements of lhs is greater-or-equal than rhs.
Note: This is not a lexical comparison.
Args:
- rhs (
Self
): Right hand side tuple.
Returns:
The comparison result.
__add__
__add__(self: Self, rhs: Self) -> Self
Performs element-wise integer add.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
__sub__
__sub__(self: Self, rhs: Self) -> Self
Performs element-wise integer subtract.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
__mul__
__mul__(self: Self, rhs: Self) -> Self
Performs element-wise integer multiply.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
__floordiv__
__floordiv__(self: Self, rhs: Self) -> Self
Performs element-wise integer floor division.
Args:
- rhs (
Self
): The elementwise divisor.
Returns:
The resulting index tuple.
__rfloordiv__
__rfloordiv__(self: Self, rhs: Self) -> Self
Floor divides rhs by this object.
Args:
- rhs (
Self
): The value to elementwise divide by self.
Returns:
The resulting index tuple.
__len__
__len__(self: Self) -> Int
Returns the size of the tuple.
Returns:
The tuple size.
as_tuple
as_tuple(self: Self) -> StaticTuple[Int, size]
Converts this StaticIntTuple to StaticTuple.
Returns:
The corresponding StaticTuple object.
flattened_length
flattened_length(self: Self) -> Int
Returns the flattened length of the tuple.
Returns:
The flattened length of the tuple.
remu
remu(self: Self, rhs: Self) -> Self
Performs element-wise integer unsigned modulo.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
__str__
__str__(self: Self) -> String
Get the tuple as a string.
Returns:
A string representation.
format_to
format_to(self: Self, inout writer: Formatter)
Formats this int tuple to the provided formatter.
Args:
- writer (
Formatter
): The formatter to write to.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
😔 What went wrong?