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

idx2crd2

def idx2crd2(idx: IntTuple, shape: IntTuple, _stride: IntTuple) -> IntTuple

Convert a linear index to coordinates.

This function handles the actual conversion logic for different input combinations.

Notes:

  • Handles four cases: tuple-tuple-tuple, tuple-int-int, int-tuple-tuple, and int-int-int.
  • When input shapes don't match, abort() will be called.

Args:

  • โ€‹idx (IntTuple): The linear index to convert.
  • โ€‹shape (IntTuple): The shape of the tensor/array.
  • โ€‹_stride (IntTuple): Custom strides to use for the conversion. If empty, strides are computed from the shape using prefix_product.

Returns:

IntTuple: A new IntTuple containing the coordinates corresponding to the linear index.

Was this page helpful?