Mojo function
coalesce
coalesce[LayoutType: TensorLayout, //](layout: LayoutType) -> Layout[*?, *?]
Simplifies a layout by merging contiguous dimensions.
Iterates over the flattened (shape, stride) pairs and:
- Skips shape-1 dimensions.
- Merges a dimension into the previous one when
prev_shape * prev_stride == current_stride(contiguous). - Otherwise starts a new dimension.
The result is the simplest layout that maps coordinates to the same linear offsets as the original.
Example:
from layout.tile_layout import Layout, coalesce, row_major, Idx
# A row-major 2x4 layout has contiguous strides -> coalesces to 1D
var layout = row_major[2, 4]()
var coalesced = coalesce(layout) # shape (8,), stride (1,)Parameters:
- LayoutType (
TensorLayout): The type of the input layout.
Args:
- layout (
LayoutType): The layout to coalesce.
Returns:
Layout: A new layout with contiguous dimensions merged.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!