Open piever opened 5 years ago
I just ran into this problem:
julia> using AxisArrays
julia> using Unitful: μm
julia> img = AxisArray(ones(10, 10), Axis{:x}(1μm:1μm:10μm), Axis{:y}(1μm:1μm:10μm));
julia> img[Axis{:x}(atindex(-2μm .. 2μm, 5)), Axis{:y}(atindex(-2μm .. 2μm, 5))]
2-dimensional AxisArray{Float64,2,...} with axes:
:x_sub, -2 μm:1 μm:2 μm
:y_sub, -2 μm:1 μm:2 μm
And data, a 5×5 Array{Float64,2}:
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
julia> img[Axis{:x}(atindex(-2μm .. 2μm, 1)), Axis{:y}(atindex(-2μm .. 2μm, 5))]
ERROR: BoundsError: attempt to access 10×10 Array{Float64,2} at index [[-1, 0, 1, 2, 3], [3, 4, 5, 6, 7]]
Stacktrace:
[1] throw_boundserror(::Array{Float64,2}, ::Tuple{AxisArray{Int64,1,UnitRange{Int64},Tuple{Axis{:sub,StepRange{Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}},Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}}}}}},AxisArray{Int64,1,UnitRange{Int64},Tuple{Axis{:sub,StepRange{Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}},Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}}}}}}}) at ./abstractarray.jl:538
[2] checkbounds at ./abstractarray.jl:503 [inlined]
[3] _getindex at ./multidimensional.jl:669 [inlined]
[4] getindex at ./abstractarray.jl:981 [inlined]
[5] getindex at /home/tlnagy/.julia/packages/AxisArrays/YXhV4/src/indexing.jl:100 [inlined]
[6] getindex_converted at /home/tlnagy/.julia/packages/AxisArrays/YXhV4/src/indexing.jl:126 [inlined]
[7] getindex(::AxisArray{Float64,2,Array{Float64,2},Tuple{Axis{:x,StepRange{Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}},Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}}}},Axis{:y,StepRange{Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}},Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}}}}}}, ::Axis{:x,AxisArrays.IntervalAtIndex{Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}}}}, ::Axis{:y,AxisArrays.IntervalAtIndex{Unitful.Quantity{Int64,𝐋,Unitful.FreeUnits{(μm,),𝐋,nothing}}}}) at /home/tlnagy/.julia/packages/AxisArrays/YXhV4/src/indexing.jl:119
[8] top-level scope at REPL[5]:1
This issue essentially negates the usefulness of atindex
for me.
@timholy any thoughts on the performance implications of returning an array with an eltype of Union{T, Missing}
?
bump
I was thinking that often when takie
atindex
windows one can easily go out of bounds of the originalArray
(when one index is near the boundary). I was wondering whether it'd make sense to have "softer"atindex
that returns arrays of eltypeUnion{T, Missing}
and simply givesmissing
for the out of bound part.