Skip to main content

Mojo function

make_ordered_layout

make_ordered_layout(shape: IntTuple[origin], order: IntTuple[origin]) -> Layout

Creates a layout with strides ordered according to a specified traversal order.

This function generates a compact (bijective) layout where the stride values follow the traversal order specified by the order parameter. This allows creating layouts with custom memory traversal patterns while maintaining a compact memory representation.

Example:

from layout import IntTuple, Layout
from layout.layout import make_ordered_layout

# Create a layout with shape (2,3,4,5) where dimensions are traversed
# in the order: dim0, dim3, dim2, dim1
var layout = make_ordered_layout(
IntTuple(2, 3, 4, 5),
IntTuple(1, 4, 3, 2)
)
# Result: Layout with shape (2,3,4,5) and stride (1,24,6,2)
from layout import IntTuple, Layout
from layout.layout import make_ordered_layout

# Create a layout with shape (2,3,4,5) where dimensions are traversed
# in the order: dim0, dim3, dim2, dim1
var layout = make_ordered_layout(
IntTuple(2, 3, 4, 5),
IntTuple(1, 4, 3, 2)
)
# Result: Layout with shape (2,3,4,5) and stride (1,24,6,2)

.

Args:

  • shape (IntTuple[origin]): The shape of the layout.
  • order (IntTuple[origin]): The traversal order priority (lower values indicate higher priority).

Returns:

A Layout with the specified shape and strides ordered according to the traversal order.

Was this page helpful?