Deeploy.TilingExtension.TilingCodegen.padShape

Deeploy.TilingExtension.TilingCodegen.padShape(shape: Tuple[int, ...], rank: int) Tuple[int, ...]

Pad a shape tuple to a target rank by prepending ones.

Extends a shape tuple to a higher dimensionality by adding leading dimensions of size 1. This is useful for broadcasting operations and ensuring consistent tensor ranks.

Parameters:
  • shape (Tuple[int, ...]) – The original shape tuple to pad.

  • rank (int) – The target rank (number of dimensions) for the padded shape.

Returns:

The padded shape tuple with leading dimensions of size 1.

Return type:

Tuple[int, …]

Raises:

AssertionError – If the target rank is smaller than the current shape’s rank.

Examples

>>> padShape((3, 4), 4)
(1, 1, 3, 4)
>>> padShape((5,), 3)
(1, 1, 5)