-
-
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 inconsistant logical index behavior #45869
Conversation
a5a6184
to
b73a6fa
Compare
16220c3
to
10b912e
Compare
Who could review this? @StefanKarpinski? |
b252b79
to
feb5aa1
Compare
@mbauman would be a good person to review when he has the chance. |
5d6a1ed
to
1e99dcc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to leave this languishing so long — I'm pretty sure I've tried reviewing it long ago but it's pretty complicated... and then I forgot about it. See my comments, I think it'd be good to simplify/coalesce some of this logic while we're here instead of making it yet more complicated. It feels like this is missing a primitive — maybe an internal function like _peel_axes_for_index
(that would effectively do a peel
for the appropriate number of axes) would help simplify many of these functions? I've been trying to get such a refactor written but I've simply not had time to see it to the end yet.
This no more influence inference on master.
…only index variable. `zeros(2,3,4)[2, 1]` is always invalid, thus this optimization is illegal for trailing dimension.
Implement `checkbounds` using `to_indices` style. The behavior of non-logical doesn't change. While for `AbstractArray{Bool,N}`s, they would behaves like `Vector{CartesianIndex{N}}` after this commit, if its shape matches the indexed dimensions. Thus the trailing singleton dimensions in boolean array would be ingnored only when we have comsumed all of the src dimensions. The test change includes: 1. disallow `zeros(2,2)[trues(1,2), 1]` 2. allow `zeros(2,2)[trues(2,2,1)]`
Co-authored-by: Matt Bauman <mbauman@gmail.com>
In order to adapt CUDA.jl to this, which requires iteratable logical indices too, is this the correct approach? # we cannot use Base.LogicalIndex, which does not support indexing but requires iteration.
Base.to_index(::CuArray, I::AbstractArray{Bool}) = findall(I)
if VERSION >= v"1.11.0-DEV.1157"
# for this PR
Base.to_indices(A::CuArray, I::Tuple{AbstractArray{Bool}}) = (Base.to_index(A, I[1]),)
else
# what we used to have
Base.to_indices(A::CuArray, inds,
I::Tuple{Union{Array{Bool,N}, BitArray{N}}}) where {N} =
(Base.to_index(A, I[1]),)
end |
Yes, it should recover the needed overloading. |
BitArray
/Array{Bool}
to index,to_indices
has an optimiztion for linear-iteratable case.But the corresponding check is not correct. IIUC, this optimization is legal only when the Boolen array is the only index provided.
The first commit fix it and widen this optimization to all Boolen array.
Before this PR
After
If there's only one index variable, singleton dimension wil not be ignored. The second commit fix it. (close Incorrect behavior of logical indexing #45867)