JuliaArrays / AxisArrays.jl

Performant arrays where each dimension can have a named axis with values
http://JuliaArrays.github.io/AxisArrays.jl/latest/
Other
200 stars 41 forks source link

Logical indexing on views of AxisArrays leads to stackoverflow errors #179

Open tlnagy opened 4 years ago

tlnagy commented 4 years ago
julia> using AxisArrays

julia> img = AxisArray(zeros(20,20, 10));

julia> slice = view(img, :, :, 1);

julia> slice[1:10, :] .= 1.0;

julia> view(slice, slice .> 0.0)
ERROR: StackOverflowError:
Stacktrace:
 [1] view(::AxisArray{Float64,2,SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Int64},true},Tuple{Axis{:row,Base.OneTo{Int64}},Axis{:col,Base.OneTo{Int64}}}}, ::Array{CartesianIndex{2},1}, ::Function) at /home/tlnagy/.julia/packages/AxisArrays/YXhV4/src/indexing.jl:124 (repeats 6187 times)
 [2] view(::AxisArray{Float64,2,SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Int64},true},Tuple{Axis{:row,Base.OneTo{Int64}},Axis{:col,Base.OneTo{Int64}}}}, ::BitArray{2}) at /home/tlnagy/.julia/packages/AxisArrays/YXhV4/src/indexing.jl:122
 [3] top-level scope at REPL[5]:1

while a copy operation leads to the correct behavior:

julia> slice[slice .> 0.0]
1-dimensional AxisArray{Float64,1,...} with axes:
    :row, Base.OneTo(200)
And data, a 200-element Array{Float64,1}:
 1.0
 ⋮  
 ⋮  
 ⋮  
 1.0

The same operation on standard Julia arrays works as expected, this is using AxisArrays v0.4.2

mcabbott commented 4 years ago

Not sure how to fix this, but here is another example, and another related error:

x = AxisArray(rand(3,4)) # no errors with  x = rand(3,4)
v = view(x, :, 1:2)

b = rand(6) .> 0.5 # BitArray{1}
v[b]
view(v, b) # BoundsError: attempt to access 3×2 view(::Array{Float64,2}, :, 1:2) with eltype Float64 at index [[3, 5, 6], Base.Slice(Base.OneTo(2))]

m = rand(3,2) .> 0.5 # BitArray{2}
v[m]
view(v, m) # StackOverflowError, view(::AxisArray