Skip to content

Conversation

@kgryte
Copy link
Contributor

@kgryte kgryte commented Dec 8, 2025

This PR

  • resolves RFC: add broadcast_shapes to the specification #893 by adding support for broadcast_shapes to the specification.
  • follows NumPy et al in supporting an arbitrary number of input shapes to be broadcasted.
  • specifies that only shapes which contain integers are explicitly supported. For shapes containing sentinel values such as None for a dimension of unknown size, behavior is left unspecified and thus implementation-defined.

@kgryte kgryte added API extension Adds new functions or objects to the API. topic: Manipulation Array manipulation and transformation. labels Dec 8, 2025
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kgryte! Overall LGTM and seems good to add this function to the standard. A few comments with the "unknown shape" one the key thing to discuss.

Returns
-------
out: Tuple[int, ...]
a broadcasted shape.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably say something like "The shape should match the regular broadcasting rules as documented in :ref:broadcasting" to make the specification a little bit more tight.

- If not provided one or more arguments, the function **must** return an empty tuple.
.. note::
Array libraries which build computation graphs (e.g., ndonnx and Dask) commonly support shapes having dimensions of unknown size. If a shape contains a value other than an integer (e.g., ``None`` for a dimension of unknown size), behavior is unspecified and thus implementation-defined. Array-conforming libraries **may** choose to propagate such values (e.g., if a shape contains a dimension size of ``None``, the returned broadcasted shape also has a corresponding dimension having a size equal to ``None``) or raise an exception.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be phrased such that it works for computation graphs in the expected manner I believe, since the broadcasting math is abstract anyway and any sentinels can propagate correctly. To be discussed in the next call I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API extension Adds new functions or objects to the API. topic: Manipulation Array manipulation and transformation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: add broadcast_shapes to the specification

2 participants