Skip to main content
Log in

Mojo function

idx2crd

idx2crd(idx: IntTuple[origin], shape: IntTuple[origin]) -> 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[origin]): The linear index to convert.
  • shape (IntTuple[origin]): The shape of the tensor/array.

Returns:

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

idx2crd(idx: IntTuple[origin], shape: IntTuple[origin], _stride: IntTuple[origin]) -> IntTuple

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

Args:

  • idx (IntTuple[origin]): The linear index to convert.
  • shape (IntTuple[origin]): The shape of the tensor/array.
  • _stride (IntTuple[origin]): Custom strides to use for the conversion.

Returns:

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