Index
Module
Implements StaticIntTuple
which is commonly used to represent N-D indices.
Aliases:
mlir_bool = scalar<bool>
StaticIntTuple
A base struct that implements size agnostic index functions.
Parameters:
- size (
Int
): The size of the tuple.
Fields:
data
The underlying storage of the tuple value.
Functions:
__init__
__init__() -> Self
Constructs a static int tuple of the given size.
Returns:
The constructed tuple.
__init__(value: index) -> Self
Constructs a sized 1 static int tuple of given the element value.
Args:
- value (
index
): The initial value.
Returns:
The constructed tuple.
__init__(*elems: Int) -> Self
Constructs a static int tuple given a set of arguments.
Args:
- elems (
*Int
): The elements to construct the tuple.
Returns:
The constructed tuple.
__init__(values: VariadicList[Int]) -> Self
Create a tuple constant using the specified values.
Args:
- values (
VariadicList[Int]
): The list of values.
Returns:
A tuple with the values filled in.
__init__(values: DimList) -> Self
Create a tuple constant using the specified values.
Args:
- values (
DimList
): The list of values.
Returns:
A tuple with the values filled in.
__init__(data: StaticTuple[size, Int]) -> Self
__getitem__
__getitem__(self: Self, index: Int) -> Int
Get an element from the tuple by index.
Args:
- index (
Int
): The element index.
Returns:
The tuple element value.
__setitem__
__setitem__[index: Int](self: Self&, val: Int)
Set an element in the tuple at the given static index.
Parameters:
- index (
Int
): The element index.
Args:
- val (
Int
): The value to store.
__setitem__(self: Self&, index: Int, val: Int)
Set an element in the tuple at the given index.
Args:
- index (
Int
): The element index. - val (
Int
): The value to store.
__lt__
__lt__(self: Self, rhs: Self) -> Bool
Compare 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 comparisionn result.
__le__
__le__(self: Self, rhs: Self) -> Bool
Compare 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 comparisionn result.
__eq__
__eq__(self: Self, rhs: Self) -> Bool
Compare 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
Compare 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
Compare 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 comparisionn result.
__ge__
__ge__(self: Self, rhs: Self) -> Bool
Compare 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 comparisionn result.
__add__
__add__(self: Self, rhs: Self) -> Self
Element-wise integer add.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
__sub__
__sub__(self: Self, rhs: Self) -> Self
Element-wise integer subtract.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
__mul__
__mul__(self: Self, rhs: Self) -> Self
Element-wise integer multiply.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
__floordiv__
__floordiv__(self: Self, rhs: Self) -> Self
Element-wise integer floor division.
Args:
- rhs (
Self
): Right hand side operand.
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[size, Int]
Convert 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
Element-wise integer unsigned modulo.
Args:
- rhs (
Self
): Right hand side operand.
Returns:
The resulting index tuple.
Index
Index(x: Int) -> StaticIntTuple[1]
Construct a 1-D Index from the given value.
Args:
- x (
Int
): The initial value.
Returns:
The constructed StaticIntTuple.
Index(x: Int, y: Int) -> StaticIntTuple[2]
Construct a 2-D Index from the given values.
Args:
- x (
Int
): The 1st initial value. - y (
Int
): The 2nd initial value.
Returns:
The constructed StaticIntTuple.
Index(x: Int, y: Int, z: Int) -> StaticIntTuple[3]
Construct a 3-D Index from the given values.
Args:
- x (
Int
): The 1st initial value. - y (
Int
): The 2nd initial value. - z (
Int
): The 3nd initial value.
Returns:
The constructed StaticIntTuple.
Index(x: Int, y: Int, z: Int, w: Int) -> StaticIntTuple[4]
Construct a 4-D Index from the given values.
Args:
- x (
Int
): The 1st initial value. - y (
Int
): The 2nd initial value. - z (
Int
): The 3nd initial value. - w (
Int
): The 4th initial value.
Returns:
The constructed StaticIntTuple.
Index(x: Int, y: Int, z: Int, w: Int, v: Int) -> StaticIntTuple[5]
Construct a 5-D Index from the given values.
Args:
- x (
Int
): The 1st initial value. - y (
Int
): The 2nd initial value. - z (
Int
): The 3nd initial value. - w (
Int
): The 4th initial value. - v (
Int
): The 5th initial value.
Returns:
The constructed StaticIntTuple.
product
product[size: Int](tuple: StaticIntTuple[size], end_idx: Int) -> Int
Compute a product of values in the tuple up to the given index.
Parameters:
- size (
Int
): The tuple size.
Args:
- tuple (
StaticIntTuple[size]
): The tuple to get a product of. - end_idx (
Int
): The end index.
Returns:
The product of all tuple elements in the given range.
product[size: Int](tuple: StaticIntTuple[size], start_idx: Int, end_idx: Int) -> Int
Compute a product of values in the tuple in the given index range.
Parameters:
- size (
Int
): The tuple size.
Args:
- tuple (
StaticIntTuple[size]
): The tuple to get a product of. - start_idx (
Int
): The start index of the range. - end_idx (
Int
): The end index of the range.
Returns:
The product of all tuple elements in the given range.