Skip to content
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

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

Open
tlnagy opened this issue Feb 20, 2020 · 1 comment
Open

Comments

@tlnagy
Copy link

tlnagy commented Feb 20, 2020

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
Copy link
Contributor

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

mcabbott pushed a commit to mcabbott/AxisKeys.jl that referenced this issue Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants