index

Module

Implements StaticIntTuple which is commonly used to represent N-D indices.

You can import these APIs from the utils package. For example:

from utils.index import StaticIntTuple

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 (StaticTuple[size, Int]): The underlying storage of the tuple value.

Functions:

__init__

static __init__() -> Self

Constructs a static int tuple of the given size.

Returns:

The constructed tuple.

static __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.

static __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.

static __init__(elem: Int) -> Self

Constructs a static int tuple given a set of arguments.

Args:

  • elem (Int): The elem to splat into the tuple.

Returns:

The constructed tuple.

static __init__(values: VariadicList[Int]) -> Self

Creates a tuple constant using the specified values.

Args:

  • values (VariadicList[Int]): The list of values.

Returns:

A tuple with the values filled in.

static __init__(values: DimList) -> Self

Creates a tuple constant using the specified values.

Args:

  • values (DimList): The list of values.

Returns:

A tuple with the values filled in.

static __init__(data: StaticTuple[size, Int]) -> Self

__getitem__

static __getitem__(self: Self, index: Int) -> Int

Gets an element from the tuple by index.

Args:

  • index (Int): The element index.

Returns:

The tuple element value.

__setitem__

static __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.

static __setitem__(inout self: Self, index: Int, val: Int)

Sets an element in the tuple at the given index.

Args:

  • index (Int): The element index.
  • val (Int): The value to store.

__lt__

static __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__

static __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__

static __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__

static __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__

static __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__

static __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__

static __add__(self: Self, rhs: Self) -> Self

Performs element-wise integer add.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

__sub__

static __sub__(self: Self, rhs: Self) -> Self

Performs element-wise integer subtract.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

__mul__

static __mul__(self: Self, rhs: Self) -> Self

Performs element-wise integer multiply.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

__floordiv__

static __floordiv__(self: Self, rhs: Self) -> Self

Performs element-wise integer floor division.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

__len__

static __len__(self: Self) -> Int

Returns the size of the tuple.

Returns:

The tuple size.

as_tuple

static as_tuple(self: Self) -> StaticTuple[size, Int]

Converts this StaticIntTuple to StaticTuple.

Returns:

The corresponding StaticTuple object.

flattened_length

static flattened_length(self: Self) -> Int

Returns the flattened length of the tuple.

Returns:

The flattened length of the tuple.

remu

static remu(self: Self, rhs: Self) -> Self

Performs element-wise integer unsigned modulo.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

Index

static Index(x: Int) -> StaticIntTuple[1]

Constructs a 1-D Index from the given value.

Args:

  • x (Int): The initial value.

Returns:

The constructed StaticIntTuple.

static Index(x: Int, y: Int) -> StaticIntTuple[2]

Constructs 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.

static Index(x: Int, y: Int, z: Int) -> StaticIntTuple[3]

Constructs 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.

static Index(x: Int, y: Int, z: Int, w: Int) -> StaticIntTuple[4]

Constructs 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.

static Index(x: Int, y: Int, z: Int, w: Int, v: Int) -> StaticIntTuple[5]

Constructs 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

static product[size: Int](tuple: StaticIntTuple[size], end_idx: Int) -> Int

Computes 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.

static product[size: Int](tuple: StaticIntTuple[size], start_idx: Int, end_idx: Int) -> Int

Computes 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.