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 42 forks source link

to_index now throws an ArgumentException instead of an UndefVarError … #51

Closed ajkeller34 closed 8 years ago

ajkeller34 commented 8 years ago

…when given repeated axes.

There is a TODO in indexing.jl asking whether or not AxisArrays should allow indexing with repeated axes. This PR does not make a decision about that, but on master the expected ErrorException is not thrown:

julia> using AxisArrays
INFO: Recompiling stale cache file /Users/ajkeller/.julia/lib/v0.5/AxisArrays.ji for module AxisArrays.

julia> A = AxisArray(rand(2,2), :x, :y)
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, Base.OneTo(2)
    :y, Base.OneTo(2)
And data, a 2×2 Array{Float64,2}:
 0.695732   0.261082
 0.0772629  0.286141

julia> A[Axis{:y}(1), Axis{:y}(1)]
ERROR: UndefVarError: y not defined
 in to_index at /Users/ajkeller/.julia/v0.5/AxisArrays/src/indexing.jl:106 [inlined]
 in getindex(::AxisArrays.AxisArray{Float64,2,Array{Float64,2},Tuple{AxisArrays.Axis{:x,Base.OneTo{Int64}},AxisArrays.Axis{:y,Base.OneTo{Int64}}}}, ::AxisArrays.Axis{:y,Int64}, ::AxisArrays.Axis{:y,Int64}) at /Users/ajkeller/.julia/v0.5/AxisArrays/src/indexing.jl:76

In this PR, in addition to displaying the expected error message I've made it an ArgumentError rather than an ErrorException:

 julia> using AxisArrays
INFO: Recompiling stale cache file /Users/ajkeller/.julia/lib/v0.5/AxisArrays.ji for module AxisArrays.

julia> A = AxisArray(rand(2,2), :x, :y)
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, Base.OneTo(2)
    :y, Base.OneTo(2)
And data, a 2×2 Array{Float64,2}:
 0.698423  0.522879
 0.957749  0.178753

julia> A[Axis{:y}(1), Axis{:y}(1)]
ERROR: ArgumentError: multiple indices provided on axis y
 in getindex(::AxisArrays.AxisArray{Float64,2,Array{Float64,2},Tuple{AxisArrays.Axis{:x,Base.OneTo{Int64}},AxisArrays.Axis{:y,Base.OneTo{Int64}}}}, ::AxisArrays.Axis{:y,Int64}, ::AxisArrays.Axis{:y,Int64}) at /Users/ajkeller/.julia/v0.5/AxisArrays/src/indexing.jl:76

I'll keep working my way towards a PR for atvalue as discussed earlier, I'm just trying to understand indexing better first.

ajkeller34 commented 8 years ago

(I didn't say it explicitly, but the problem was that the axis name, a symbol, was being interpolated into the expression returned from the generated function, and so error saw the axis name not as a string but as a symbol to look up.)

ajkeller34 commented 8 years ago

The travis failure looks unrelated, not sure what happened.

mbauman commented 8 years ago

Yup, looks like some sort of precompilation-related error. I restarted the builds and they passed.