Skip to content

Clarify the required semantics for broadcasting with __setitem__ #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion spec/API_specification/broadcasting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,17 @@ The following examples demonstrate array shapes which do **not** broadcast.
In-place Semantics
------------------

As implied by the broadcasting algorithm, in-place element-wise operations must not change the shape of the in-place array as a result of broadcasting.
As implied by the broadcasting algorithm, in-place element-wise operations (including ``__setitem__``) must not change the shape of the in-place array as a result of broadcasting. Such operations should only be supported in the case where the right-hand operand can broadcast to the shape of the left-hand operand, after any indexing operations are performed.

For example:

::

x = empty((2, 3, 4))
a = empty((1, 3, 4))

# This is OK. The shape of a, (1, 3, 4), can broadcast to the shape of x[...], (2, 3, 4)
x[...] = a

# This is not allowed. The shape of a, (1, 3, 4), can NOT broadcast to the shape of x[1, ...], (3, 4)
x[1, ...] = a