Fix collect of non-reshaped reinterpret of an IndexSCartesian2 array - #63352
Conversation
| function IndexStyle(::Type{ReinterpretArray{T,N,S,A,false}}) where {T,N,S,A<:AbstractArray{S,N}} | ||
| style = IndexStyle(A) | ||
| # a size change invalidates the parent's `IndexSCartesian2` (#63305) | ||
| style isa IndexSCartesian2 && aligned_sizeof(T) != aligned_sizeof(S) && return IndexCartesian() |
There was a problem hiding this comment.
I wonder if it would be safer to have a white list of IndexStyle to pass through, instead of an explicit set of IndexStyles that need to be blocked from passing through.
|
Good point, thanks @nhz2 . I'll switch to a whitelist so that only |
|
I'm having a hard time understanding |
|
Yeah, that confused me at first too. The problem is that the non-reshaped With the whitelist change, this method now only ever returns |
226702b to
db416f4
Compare
Fixes #63305
A non-reshaped
reinterpretinherited its parent'sIndexSCartesian2{K}index style. Buteachindexfor that style is forwarded to the parent, so when the element size changes (and with it the array's axes), iteration and thereforecollectvisited the wrong elements. This makes it fall back toIndexCartesian()in that case. Same-size reinterprets keep the fast path.The same pattern may also affect
reinterpret(reshape, T, ...)when it drops the leading dimension of anIndexSCartesian2parent. Happy to handle that here or in a follow-up.Disclosure: I used claude to help find the root cause and draft this patch. I have reviewed the change and understand it.