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

crd2idx

crd2idx[Index: CoordLike, Shape: CoordLike, Stride: CoordLike, out_type: DType = DType.int64](crd: Index, shape: Shape, stride: Stride) -> Scalar[out_type]

Calculate the linear index from a coordinate tuple.

The dot product is computed at out_type precision (each coord * stride term is evaluated after narrowing both operands to out_type). Callers that pick a narrow out_type (e.g. uint32) are responsible for ensuring every per-dim product and their sum fit in that type. The default DType.int64 is wide enough for realistic layouts. See _crd2idx_flat.

Parameters:

  • Index (CoordLike): The coordinate type (must be CoordLike).
  • Shape (CoordLike): The shape type (must be CoordLike).
  • Stride (CoordLike): The stride type (must be CoordLike).
  • out_type (DType): The output scalar type.

Args:

  • crd (Index): The multi-dimensional coordinate.
  • shape (Shape): The shape of the tensor.
  • stride (Stride): The stride of the tensor.

Returns:

Scalar[out_type]: The linear index corresponding to the coordinate.