-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]search & findThe find* family of functionsThe find* family of functions
Description
This behavior strikes me as inconsistent:
julia> x1 = zeros(Bool, (Base.OneTo(2), Base.OneTo(0)))
2×0 Array{Bool,2}
julia> x2 = zeros(Bool, (Base.OneTo(0), Base.OneTo(2)))
0×2 Array{Bool,2}
julia> first(keys(x1))
CartesianIndex(1, 1)
julia> first(keys(x2))
CartesianIndex(1, 1)
julia> last(keys(x1))
CartesianIndex(2, 0)
julia> last(keys(x2))
CartesianIndex(0, 2)
julia> findnext(x1, first(keys(x1)))
julia> findnext(x2, first(keys(x2)))
ERROR: BoundsError: attempt to access 0×2 Array{Bool,2} at index [1, 1]
Stacktrace:
[1] getindex at ./array.jl:810 [inlined]
[2] getindex at ./multidimensional.jl:557 [inlined]
[3] findnext(::Array{Bool,2}, ::CartesianIndex{2}) at ./array.jl:1728
[4] top-level scope at REPL[32]:1I had expected both calls to findnext to return nothing.
Honing in, the inconsistency arises because of
julia> CartesianIndex(2, 0) > CartesianIndex(1, 1)
false
julia> CartesianIndex(0, 2) > CartesianIndex(1, 1)
trueand so the check at
Line 1726 in 4c1e3c0
| i > l && return nothing |
I believe the intention in findnext is to compare CartesianIndexs in a way that agrees with the corresponding comparison on the LinearIndex into the array. For example:
julia> Base._sub2ind(x1, Tuple(first(keys(x1)))...)
1
julia> Base._sub2ind(x1, Tuple(last(keys(x1)))...)
0
julia> Base._sub2ind(x2, Tuple(first(keys(x2)))...)
1
julia> Base._sub2ind(x2, Tuple(last(keys(x2)))...)
0(I tried on Julia 1.4 and Julia 1.5)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]search & findThe find* family of functionsThe find* family of functions