Skip to main content

Mojo function

composition

composition(layout_a: Layout, layout_b: Layout) -> Layout

Composes two layouts to create a new layout.

This function creates a new layout by composing two layouts, where the first layout defines the outer structure and the second layout defines the inner structure.

The new layout is compatible with layout_b (that is, it has the same size and every set of coordinates in layout_b has an equivalent in the new layout). You can think of layout_b as selecting a subset of elements from layout_a.

Example:

from layout.layout import Layout, IntTuple
from layout.layout import composition

# Compose a row-major layout with a tiling layout
var base = Layout.row_major(6, 8)
var tiling = Layout(IntTuple(3, 2), IntTuple(1, 3))
var composed = composition(base, tiling)
# Result: A layout that represents a 3x2 tile from
# layout_a
from layout.layout import Layout, IntTuple
from layout.layout import composition

# Compose a row-major layout with a tiling layout
var base = Layout.row_major(6, 8)
var tiling = Layout(IntTuple(3, 2), IntTuple(1, 3))
var composed = composition(base, tiling)
# Result: A layout that represents a 3x2 tile from
# layout_a

.

Args:

  • layout_a (Layout): The outer layout.
  • layout_b (Layout): The inner layout.

Returns:

A new layout representing the composition of the two layouts.

composition(layout_a: Layout, tiler: List[Layout]) -> Layout

Composes a layout with a list of layouts to create a hierarchical layout.

This function creates a new layout by composing each element of the first layout with the corresponding element in the tiler list. If the tiler list is shorter than the layout, the remaining elements from the layout are appended unchanged.

Example:

from layout import Layout, LayoutList, IntTuple
from layout.layout import composition

# Compose a layout with a list of tiling layouts
var base = Layout.row_major(6, 8)
var tilers = LayoutList()
tilers.append(Layout(IntTuple(2, 2), IntTuple(1, 2)))
tilers.append(Layout(IntTuple(3, 3), IntTuple(1, 3)))
var composed = composition(base, tilers)
# Result: A layout with hierarchical tiling based on the tiler list
from layout import Layout, LayoutList, IntTuple
from layout.layout import composition

# Compose a layout with a list of tiling layouts
var base = Layout.row_major(6, 8)
var tilers = LayoutList()
tilers.append(Layout(IntTuple(2, 2), IntTuple(1, 2)))
tilers.append(Layout(IntTuple(3, 3), IntTuple(1, 3)))
var composed = composition(base, tilers)
# Result: A layout with hierarchical tiling based on the tiler list

.

Args:

  • layout_a (Layout): The base layout to compose with the tiler.
  • tiler (List[Layout]): A list of layouts to compose with the base layout.

Returns:

A new layout representing the composition of the base layout with the tiler.

Was this page helpful?