IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

idx2crd2

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.