-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix assignment to 0-dim array indexed by CartesianIndices{0} #34893
Conversation
I found another case that has regressed, and this PR right now doesn't fix.
|
8283e7f
to
0de6f2a
Compare
It appears simply preserving all instances of |
Ah, very nice, thank you! There's an ambiguity when there are no indices — was this a scalar assignment or a non scalar assignment? #24086 is the root cause here, but this is a great fix. Thanks! |
Right you are. Thanks again! |
…ng#34893) * Fix assignment to 0-dim array indexed by CartesianIndices{0} * Fix assigning element into ≥1-dim arrays from 0-dim array
* Fix assignment to 0-dim array indexed by CartesianIndices{0} * Fix assigning element into ≥1-dim arrays from 0-dim array
The change in PR #31214 replaced
CartesianIndices
in the indexing tuple with their constituent ranges. This broke assignment to 0-dimensional arrays which have been indexed by aCartesianIndices{0}
, e.g.This is because previously the
CartesianIndices{0}
(hereafterCI0
) was preserved through the call toto_indices()
:but now the empty tuple is returned instead:
and that changes which internal implementation of
setindex!
is dispatched to.This PR fixes the issue by tweaking the tuple reduction performed by
to_indices()
. The result is thatduring the tuple reduction, a case where only [trailing]
CI0
s remain is shortcut and returns just a singleCI0
index.With this PR:
The one thing I couldn't figure out is how to avoid an unnecessary trailing
CI0
if a concrete index precedes it — (my attempts lead toto_indices()
method ambiguities) — but there's always at most a single unnecessary trailingCI0
.