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).
coalesce
coalesce(layout: Layout, keep_rank: Bool = False) -> Layout
Simplifies a layout by combining dimensions with contiguous strides.
This function reduces the rank of a layout by merging dimensions that have contiguous memory layouts, resulting in a simpler but equivalent layout.
Example:
from layout import Layout, IntTuple
from layout.layout import coalesce
# A layout with shape (2, (1, 4)) and stride (1, (4, 2)) can be coalesced
var layout = Layout(IntTuple(2, IntTuple(1, 4)), IntTuple(1, IntTuple(4, 2)))
var coalesced = coalesce(layout)
# Result: Layout with shape (8) and stride (1)
Args:
- layout (
Layout): The layout to coalesce. - keep_rank (
Bool): If True, maintains the original rank of the layout. Default is False.
Returns:
Layout: A simplified layout with reduced rank where possible.