Mojo struct
Dim
@register_passable(trivial)
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
,
ExplicitlyCopyable
,
Movable
,
Stringable
,
UnknownDestructibility
,
Writable
Methods
__init__
@implicit
__init__(value: Index[3]) -> Self
Initializes Dim with an IndexList[3].
Args:
- value (
Index[3]
): The IndexList[3] representing the dimension.
@implicit
__init__[I: Index](x: I) -> Self
Initializes Dim with a single indexable value for x.
y and z dimensions are set to 1.
Parameters:
- I (
Index
): The type of the indexable value.
Args:
- x (
I
): The value for the x dimension.
__init__[I0: Index, I1: Index](x: I0, y: I1) -> Self
Initializes Dim with indexable values for x and y.
z dimension is set to 1.
Parameters:
- I0 (
Index
): The type of the first indexable value. - I1 (
Index
): The type of the second indexable value.
Args:
- x (
I0
): The value for the x dimension. - y (
I1
): The value for the y dimension.
__init__[I0: Index, I1: Index, I2: Index](x: I0, y: I1, z: I2) -> Self
Initializes Dim with indexable values for x, y, and z.
Parameters:
- I0 (
Index
): The type of the first indexable value. - I1 (
Index
): The type of the second indexable value. - I2 (
Index
): 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
__init__[I: Index](dims: Tuple[I]) -> Self
Initializes Dim with a tuple containing a single indexable value.
y and z dimensions are set to 1.
Parameters:
- I (
Index
): The type of the indexable value in the tuple.
Args:
- dims (
Tuple[I]
): A tuple with one element for x dimension.
@implicit
__init__[I0: Index, I1: Index](dims: Tuple[I0, I1]) -> Self
Initializes Dim with a tuple of two indexable values.
The z dimension is set to 1.
Parameters:
- I0 (
Index
): The type of the first indexable value in the tuple. - I1 (
Index
): 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
__init__[I0: Index, I1: Index, I2: Index](dims: Tuple[I0, I1, I2]) -> Self
Initializes Dim with a tuple of three indexable values.
Parameters:
- I0 (
Index
): The type of the first indexable value in the tuple. - I1 (
Index
): The type of the second indexable value in the tuple. - I2 (
Index
): 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__
__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:
The value of the dimension at the given index.
__str__
__str__(self) -> String
Returns a string representation of the Dim.
Returns:
String representation of this Dim object.
__repr__
__repr__(self) -> String
Returns a string representation of the Dim.
Returns:
String representation of this Dim object.
write_to
write_to[W: Writer](self, mut writer: W)
Writes a formatted string representation of the Dim.
Parameters:
- W (
Writer
): The type of writer to use for output. Must implement the Writer trait.
Args:
- writer (
W
): The Writer to write to.
z
z(self) -> Int
Returns the z dimension.
Returns:
The value of the z dimension.
y
y(self) -> Int
Returns the y dimension.
Returns:
The value of the y dimension.
x
x(self) -> Int
Returns the x dimension.
Returns:
The value of the x dimension.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!