grids.mixins.core.GridUtilsMixin.broadcast_shape_to_axes#

GridUtilsMixin.broadcast_shape_to_axes(shape: int | Sequence[int], axes_in: AxesInput, axes_out: AxesInput) Tuple[int, ...][source]#

Expand an input shape aligned to axes_in so it is broadcastable against axes_out.

This inserts singleton dimensions (1s) in the positions corresponding to any axes present in axes_out but not in axes_in, while preserving trailing non-grid dimensions.

Parameters:
  • shape (int or sequence of int) – Shape aligned with axes_in, possibly followed by extra non-grid dimensions (e.g., for vector or tensor fields). If a scalar, it is treated as (shape,).

  • axes_in (str or list of str) – The axes corresponding to the leading dimensions of shape.

  • axes_out (str or list of str) – The target axes into which the shape should be broadcastable.

Returns:

A shape tuple broadcastable over the axes in axes_out, preserving any trailing non-grid dimensions.

Return type:

tuple of int

Raises:

ValueError – If axes_in is not a subset of axes_out, or if the shape does not match the number of input axes.