Skip to main content

Mojo struct

DimList

@register_passable(trivial)

This type represents a list of dimensions. Each dimension may have a static value or not have a value, which represents a dynamic dimension.

Fields

  • value (VariadicList[Dim]): The underlying storage for the list of dimensions.

Implemented traits

AnyType, Sized, Stringable, Writable

Methods

__init__

__init__[Intable: Intable](out self, values: Tuple[Intable])

Creates a dimension list from the given list of values.

Parameters:

  • Intable (Intable): A type able to be converted to an Int.

Args:

  • values (Tuple[Intable]): The initial dim values list.

__init__[Intable: Intable](out self, values: Tuple[Intable, Intable])

Creates a dimension list from the given list of values.

Parameters:

  • Intable (Intable): A type able to be converted to an Int.

Args:

  • values (Tuple[Intable, Intable]): The initial dim values list.

__init__[Intable: Intable](out self, values: Tuple[Intable, Intable, Intable])

Creates a dimension list from the given list of values.

Parameters:

  • Intable (Intable): A type able to be converted to an Int.

Args:

  • values (Tuple[Intable, Intable, Intable]): The initial dim values list.

__init__(out self, values: VariadicList[Dim])

Creates a dimension list from the given list of values.

Args:

  • values (VariadicList[Dim]): The initial dim values list.

__init__(out self, *values: Dim)

Creates a dimension list from the given Dim values.

Args:

  • *values (Dim): The initial dim values.

__eq__

__eq__(self, rhs: Self) -> Bool

Compares two DimLists for equality.

DimLists are considered equal if all non-dynamic Dims have similar values and all dynamic Dims in self are also dynamic in rhs.

Args:

  • rhs (Self): The other DimList.

Returns:

True if the DimLists are the same.

__len__

__len__(self) -> Int

Gets the size of the DimList.

Returns:

The number of elements in the DimList.

get

get[i: Int](self) -> Int

Gets the static dimension value at a specified index.

Parameters:

  • i (Int): The dimension index.

Returns:

The static dimension value at the specified index.

at

at[i: Int](self) -> Dim

Gets the dimension at a specified index.

Parameters:

  • i (Int): The dimension index.

Returns:

The dimension at the specified index.

has_value

has_value[i: Int](self) -> Bool

Returns True if the dimension at the given index has a static value.

Parameters:

  • i (Int): The dimension index.

Returns:

Whether the specified dimension has a static value.

product

product[length: Int](self) -> Dim

Computes the product of the first length dimensions in the list.

If any are dynamic, the result is a dynamic dimension value.

Parameters:

  • length (Int): The number of elements in the list.

Returns:

The product of the first length dimensions.

product[start: Int, end: Int](self) -> Dim

Computes the product of a range of the dimensions in the list.

If any in the range are dynamic, the result is a dynamic dimension value.

Parameters:

  • start (Int): The starting index.
  • end (Int): The end index.

Returns:

The product of all the dimensions.

product(self) -> Dim

Computes the product of all the dimensions in the list.

If any are dynamic, the result is a dynamic dimension value.

Returns:

The product of all the dimensions.

contains

contains[length: Int](self, value: Dim) -> Bool

Determines whether the dimension list contains a specified dimension value.

Parameters:

  • length (Int): The number of elements in the list.

Args:

  • value (Dim): The value to find.

Returns:

True if the list contains a dimension of the specified value.

all_known

all_known[length: Int](self) -> Bool

Determines whether all dimensions are statically known.

Parameters:

  • length (Int): The number of elements in the list.

Returns:

True if all dimensions have a static value.

all_known[start: Int, end: Int](self) -> Bool

Determines whether all dimensions within [start, end) are statically known.

Parameters:

  • start (Int): The first queried dimension.
  • end (Int): The last queried dimension.

Returns:

True if all queried dimensions have a static value.

create_unknown

static create_unknown[length: Int]() -> Self

Creates a dimension list of all dynamic dimension values.

Parameters:

  • length (Int): The number of elements in the list.

Returns:

A list of all dynamic dimension values.

__str__

__str__(self) -> String

Converts the DimList to a String. The String is a comma separated list of the string representation of Dim.

Returns:

The string representation of the type.

write_to

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

Formats this DimList to the provided Writer.

Parameters:

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

Args:

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