Skip to content

Commit cb2d7bd

Browse files
authored
Clarify the required semantics for broadcasting with __setitem__ (#429)
Closes gh-424
1 parent 1229f06 commit cb2d7bd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

spec/API_specification/broadcasting.rst

+14-1
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,17 @@ The following examples demonstrate array shapes which do **not** broadcast.
112112
In-place Semantics
113113
------------------
114114

115-
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.
115+
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.
116+
117+
For example:
118+
119+
::
120+
121+
x = empty((2, 3, 4))
122+
a = empty((1, 3, 4))
123+
124+
# This is OK. The shape of a, (1, 3, 4), can broadcast to the shape of x[...], (2, 3, 4)
125+
x[...] = a
126+
127+
# This is not allowed. The shape of a, (1, 3, 4), can NOT broadcast to the shape of x[1, ...], (3, 4)
128+
x[1, ...] = a

0 commit comments

Comments
 (0)