For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo struct
Dim
struct Dim
Represents a dimension with up to three components (x, y, z).
This struct is commonly used to represent grid and block dimensions for kernel launches.
Implemented traitsβ
AnyType,
Copyable,
Deinitable,
ImplicitlyCopyable,
Movable,
RegisterPassable,
TrivialRegisterPassable,
Writable
Methodsβ
__init__β
@implicit
def __init__[I: Indexer, //](x: I) -> Self
Initializes Dim with a single indexable value for x.
y and z dimensions are set to 1.
Parameters:
- βI (
Indexer): The type of the indexable value.
Args:
- βx (
I): The value for the x dimension.
def __init__[I0: Indexer, I1: Indexer, //](x: I0, y: I1) -> Self
Initializes Dim with indexable values for x and y.
z dimension is set to 1.
Parameters:
- βI0 (
Indexer): The type of the first indexable value. - βI1 (
Indexer): The type of the second indexable value.
Args:
- βx (
I0): The value for the x dimension. - βy (
I1): The value for the y dimension.
def __init__[I0: Indexer, I1: Indexer, I2: Indexer, //](x: I0, y: I1, z: I2) -> Self
Initializes Dim with indexable values for x, y, and z.
Parameters:
- βI0 (
Indexer): The type of the first indexable value. - βI1 (
Indexer): The type of the second indexable value. - βI2 (
Indexer): The type of the third indexable value.
Args:
- βx (
I0): The value for the x dimension. - βy (
I1): The value for the y dimension. - βz (
I2): The value for the z dimension.
@implicit
def __init__[I: Indexer & Copyable, //](dims: Tuple[I]) -> Self
Initializes Dim with a tuple containing a single indexable value.
y and z dimensions are set to 1.
Parameters:
Args:
- βdims (
Tuple[I]): A tuple with one element for x dimension.
@implicit
def __init__[I0: Indexer & Copyable, I1: Indexer & Copyable, //](dims: Tuple[I0, I1]) -> Self
Initializes Dim with a tuple of two indexable values.
The z dimension is set to 1.
Parameters:
- βI0 (
Indexer&Copyable): The type of the first indexable value in the tuple. - βI1 (
Indexer&Copyable): The type of the second indexable value in the tuple.
Args:
- βdims (
Tuple[I0, I1]): A tuple with two elements: x and y dimensions.
@implicit
def __init__[I0: Indexer & Copyable, I1: Indexer & Copyable, I2: Indexer & Copyable, //](dims: Tuple[I0, I1, I2]) -> Self
Initializes Dim with a tuple of three indexable values.
Parameters:
- βI0 (
Indexer&Copyable): The type of the first indexable value in the tuple. - βI1 (
Indexer&Copyable): The type of the second indexable value in the tuple. - βI2 (
Indexer&Copyable): The type of the third indexable value in the tuple.
Args:
- βdims (
Tuple[I0, I1, I2]): Tuple with three elements: x, y, and z dimensions.
__getitem__β
def __getitem__(self, idx: Int) -> Int
Gets the dimension value at the specified index.
Args:
- βidx (
Int): The index (0 for x, 1 for y, 2 for z).
Returns:
Int: The value of the dimension at the given index.
write_toβ
def write_to(self, mut writer: T)
Writes a formatted string representation of the Dim.
Args:
- βwriter (
T): The Writer to write to.