Mojo function
crd2idx
crd2idx[: ImmutableOrigin, : ImmutableOrigin, : ImmutableOrigin, //, crd_t: IntTuple[$2], shape_t: IntTuple[$1], stride_t: IntTuple[$0], out_type: DType = uint64](crd: RuntimeTuple[crd_t, element_bitwidth=element_bitwidth, unsigned=unsigned], shape: RuntimeTuple[shape_t, element_bitwidth=element_bitwidth, unsigned=unsigned], stride: RuntimeTuple[stride_t, element_bitwidth=element_bitwidth, unsigned=unsigned]) -> SIMD[out_type, 1]
Converts multi-dimensional coordinates to a linear index.
This function is the inverse of idx2crd, transforming a set of coordinates into a flat index based on the provided shape and stride information. This is essential for mapping multi-dimensional tensor elements to linear memory.
Parameters:
- crd_t (
IntTuple[$2]
): Type of the coordinates. - shape_t (
IntTuple[$1]
): Type of the shape. - stride_t (
IntTuple[$0]
): Type of the stride. - out_type (
DType
): The output data type for the index (default: uint64).
Args:
- crd (
RuntimeTuple[crd_t, element_bitwidth=element_bitwidth, unsigned=unsigned]
): The coordinates to convert. - shape (
RuntimeTuple[shape_t, element_bitwidth=element_bitwidth, unsigned=unsigned]
): The shape of the multi-dimensional array. - stride (
RuntimeTuple[stride_t, element_bitwidth=element_bitwidth, unsigned=unsigned]
): The stride values for each dimension.
Returns:
A scalar value representing the linear index corresponding to the given coordinates.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!