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

idx2crd

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

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

Was this page helpful?