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

compact_order

def compact_order(shape: IntTuple, order: IntTuple) -> IntTuple

Create a compact stride based on shape and order.

This function generates a stride tuple where lower order numbers imply faster varying strides. The resulting shape and stride form a bijective layout.

Performance:

  • Always inlined for optimal performance in tight loops.
  • Flattens inputs and re-nests results for consistent behavior.

Example:

from layout import IntTuple
from layout.int_tuple import compact_order

# Create a compact layout with dimensions (2,3,4,5) and ordering (1,4,3,5)
var x = compact_order(IntTuple(2,3,4,5), IntTuple(1,4,3,5))  # returns (1,8,2,24)

# Create a compact layout with nested dimensions and corresponding ordering
var y = compact_order(IntTuple(2,IntTuple(3,4),5), IntTuple(1,IntTuple(2,3),4))  # returns (1,(2,6),24)

Args:

  • shape (IntTuple): The shape tuple defining dimensions.
  • order (IntTuple): The order tuple defining the relative ordering of dimensions.

Returns:

IntTuple: A stride tuple that creates a compact memory layout according to the specified order.

Was this page helpful?