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).

idx2crd

idx2crd(idx: IntTuple, shape: IntTuple) -> IntTuple

Converts a linear index to a coordinate tuple within a given shape.

This function splits an index into a coordinate within a Shape via a colexicographical enumeration of coordinates in Shape.

Args:

  • idx (IntTuple): The linear index to convert.
  • shape (IntTuple): The shape of the tensor/array.

Returns:

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

idx2crd(idx: IntTuple, shape: IntTuple, _stride: IntTuple) -> IntTuple

Converts a linear index to a coordinate tuple within a given shape using custom strides.

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.

Returns:

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