Skip to main content
Log in

Mojo struct

IndexList

@register_passable(trivial) struct IndexList[size: Int, *, element_bitwidth: Int = Int(bitwidthof[AnyTrivialRegType,__mlir_type.!kgen.target]()), unsigned: Bool = False]

A base struct that implements size agnostic index functions.

Parameters

  • size (Int): The size of the tuple.
  • element_bitwidth (Int): The bitwidth of the underlying integer element type.
  • unsigned (Bool): Whether the integer is signed or unsigned.

Aliases

  • element_type = _type_of_width[::Int,::Bool](): The underlying dtype of the integer element value.

Fields

  • data (StaticTuple[SIMD[_type_of_width[::Int,::Bool](), 1], size]): The underlying storage of the tuple value.

Implemented traits

AnyType, Comparable, Copyable, EqualityComparable, Movable, Sized, Stringable, UnknownDestructibility, Writable

Methods

__init__

__init__(out self)

Constructs a static int tuple of the given size.

@implicit __init__(out self, data: StaticTuple[SIMD[_type_of_width[::Int,::Bool](), 1], size])

Constructs a static int tuple of the given size.

Args:

  • data (StaticTuple[SIMD[_type_of_width[::Int,::Bool](), 1], size]): The StaticTuple to construct the IndexList from.

@implicit __init__(out 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.

@implicit __init__(out 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.

@implicit __init__(out 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.

@implicit __init__(out self, *elems: Int)

Constructs a static int tuple given a set of arguments.

Args:

  • *elems (Int): The elements to construct the tuple.

@implicit __init__(out self, elem: Int)

Constructs a static int tuple given a set of arguments.

Args:

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

__init__(out self, *, other: Self)

Copy constructor.

Args:

  • other (Self): The other tuple to copy from.

@implicit __init__(out self, values: VariadicList[Int])

Creates a tuple constant using the specified values.

Args:

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

__getitem__

__getitem__[idx: Int](self) -> Int

Gets an element from the tuple by index.

Parameters:

  • idx (Int): The element index.

Returns:

The tuple element value.

__getitem__(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](mut 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__[index: Int](mut self, val: SIMD[_type_of_width[::Int,::Bool](), 1])

Sets an element in the tuple at the given static index.

Parameters:

  • index (Int): The element index.

Args:

  • val (SIMD[_type_of_width[::Int,::Bool](), 1]): The value to store.

__setitem__(mut 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, 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, 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, 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, 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, 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, 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, rhs: Self) -> Self

Performs element-wise integer add.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

__sub__

__sub__(self, rhs: Self) -> Self

Performs element-wise integer subtract.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

__mul__

__mul__(self, rhs: Self) -> Self

Performs element-wise integer multiply.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

__floordiv__

__floordiv__(self, rhs: Self) -> Self

Performs element-wise integer floor division.

Args:

  • rhs (Self): The elementwise divisor.

Returns:

The resulting index tuple.

__rfloordiv__

__rfloordiv__(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) -> Int

Returns the size of the tuple.

Returns:

The tuple size.

as_tuple

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

Converts this IndexList to StaticTuple.

Returns:

The corresponding StaticTuple object.

canonicalize

canonicalize(self) -> IndexList[size]

Canonicalizes the IndexList.

Returns:

Canonicalizes the object.

flattened_length

flattened_length(self) -> Int

Returns the flattened length of the tuple.

Returns:

The flattened length of the tuple.

remu

remu(self, rhs: Self) -> Self

Performs element-wise integer unsigned modulo.

Args:

  • rhs (Self): Right hand side operand.

Returns:

The resulting index tuple.

write_to

write_to[W: Writer](self, mut writer: W)

Formats this IndexList value to the provided Writer.

Parameters:

  • W (Writer): A type conforming to the Writable trait.

Args:

  • writer (W): The object to write to.

__str__

__str__(self) -> String

Get the tuple as a string.

Returns:

A string representation.

cast

cast[type: DType](self) -> IndexList[size, element_bitwidth=Int(bitwidthof[::DType,__mlir_type.!kgen.target]()), unsigned=_is_unsigned[::DType]()]

Casts to the target DType.

Parameters:

  • type (DType): The type to cast towards.

Returns:

The list casted to the target type.

cast[*, element_bitwidth: Int = element_bitwidth, unsigned: Bool = unsigned](self) -> IndexList[size, element_bitwidth=element_bitwidth, unsigned=unsigned]

Casts to the target DType.

Parameters:

  • element_bitwidth (Int): The bitwidth to cast towards.
  • unsigned (Bool): The signess of the list.

Returns:

The list casted to the target type.