Deeploy.TilingExtension.TilingCodegen.minimizeRectangle
- Deeploy.TilingExtension.TilingCodegen.minimizeRectangle(rect: HyperRectangle, referenceShape: Sequence[int]) Tuple[HyperRectangle, Tuple[int, ...]]
Minimize a hyperrectangle by collapsing dimensions where possible.
Reduces the dimensionality of a hyperrectangle by merging consecutive dimensions where the rectangle spans the entire reference shape. This optimization is useful for memory transfers and reduces complexity.
- Parameters:
rect (HyperRectangle) – The hyperrectangle to minimize.
referenceShape (Sequence[int]) – The shape of the reference tensor that the rectangle is within.
- Returns:
A tuple containing: - The minimized HyperRectangle with collapsed dimensions - The corresponding minimized reference shape
- Return type:
Tuple[HyperRectangle, Tuple[int, …]]
- Raises:
AssertionError – If the rectangle offset is non-zero when dimensions match the reference shape (indicating the rectangle spans the full dimension).
Notes
Dimensions are collapsed from right to left. When a rectangle dimension equals the reference dimension and has zero offset, it can be merged with adjacent dimensions to reduce the overall rank.
Example
>>> rect = HyperRectangle((0, 0), (2, 2)) >>> minimizeRectangle(rect, (4, 4)) (HyperRectangle(offset=(0, 0), dims=(2, 2)), (2, 4)) >>> rect = HyperRectangle((0, 0), (2, 2)) >>> minimizeRectangle(rect, (4, 2)) (HyperRectangle(offset=(0,), dims=(4,)), (8,))