IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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:

Returns:

Scalar[out_type]: A scalar value representing the linear index corresponding to the given coordinates.

Was this page helpful?