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 function
crd2idx
def crd2idx[crd_t: IntTuple, shape_t: IntTuple, stride_t: IntTuple, out_type: DType = DType.uint64](crd: RuntimeTuple[crd_t, element_type=crd.element_type], shape: RuntimeTuple[shape_t, element_type=shape.element_type], stride: RuntimeTuple[stride_t, element_type=stride.element_type]) -> Scalar[out_type]
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): Type of the coordinates. - βshape_t (
IntTuple): Type of the shape. - βstride_t (
IntTuple): Type of the stride. - βout_type (
DType): The output data type for the index (default: uint64).
Args:
- βcrd (
RuntimeTuple[crd_t, element_type=crd.element_type]): The coordinates to convert. - βshape (
RuntimeTuple[shape_t, element_type=shape.element_type]): The shape of the multi-dimensional array. - βstride (
RuntimeTuple[stride_t, element_type=stride.element_type]): The stride values for each dimension.
Returns:
Scalar[out_type]: A scalar value representing the linear index corresponding to the given coordinates.