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,
ImplicitlyCopyable,
Movable,
Stringable,
UnknownDestructibility,
Writable
Aliases
__copyinit__is_trivial
alias __copyinit__is_trivial = IndexList[3].__copyinit__is_trivial
__del__is_trivial
alias __del__is_trivial = IndexList[3].__del__is_trivial
__moveinit__is_trivial
alias __moveinit__is_trivial = IndexList[3].__moveinit__is_trivial
Methods
__init__
@implicit
__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.
__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.
__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
__init__[I: Indexer & Copyable & Movable, //](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): A tuple with one element for x dimension.
@implicit
__init__[I0: Indexer & Copyable & Movable, I1: Indexer & Copyable & Movable, //](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&Movable): The type of the first indexable value in the tuple. - I1 (
Indexer&Copyable&Movable): The type of the second indexable value in the tuple.
Args:
- dims (
Tuple): A tuple with two elements: x and y dimensions.
@implicit
__init__[I0: Indexer & Copyable & Movable, I1: Indexer & Copyable & Movable, I2: Indexer & Copyable & Movable, //](dims: Tuple[I0, I1, I2]) -> Self
Initializes Dim with a tuple of three indexable values.
Parameters:
- I0 (
Indexer&Copyable&Movable): The type of the first indexable value in the tuple. - I1 (
Indexer&Copyable&Movable): The type of the second indexable value in the tuple. - I2 (
Indexer&Copyable&Movable): The type of the third indexable value in the tuple.
Args:
- dims (
Tuple): 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:
Int: The value of the dimension at the given index.
__str__
__str__(self) -> String
Returns a string representation of the Dim.
Returns:
String: String representation of this Dim object.
__repr__
__repr__(self) -> String
Returns a string representation of the Dim.
Returns:
String: String representation of this Dim object.
write_to
write_to(self, mut writer: T)
Writes a formatted string representation of the Dim.
Args:
- writer (
T): The Writer to write to.
z
y
x
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!