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

Gracefully error when using multidimensional indices #151

Open rofinn opened 5 years ago

rofinn commented 5 years ago

The following error is really hard to debug, particularly given the repeats 2 times which hides what the type of the input is.

Example)

julia> using AxisArrays

julia> aa = AxisArray(rand(10, 5), Axis{:time}(1:10), Axis{:name}([:a, :b, :c, :d, :e]))
10×5 AxisArray{Float64,2,Array{Float64,2},Tuple{Axis{:time,UnitRange{Int64}},Axis{:name,Array{Symbol,1}}}}:
 0.204148    0.792777   0.780203  0.222078   0.530742
 0.790793    0.684368   0.328124  0.475048   0.407242
 0.0292672   0.67966    0.540458  0.429185   0.694913
 0.932434    0.748893   0.831468  0.423212   0.496423
 0.127433    0.191755   0.404633  0.0733558  0.689208
 0.00480001  0.0853037  0.520147  0.29591    0.44223
 0.0359702   0.990168   0.636954  0.717789   0.832071
 0.0701029   0.94967    0.950602  0.2058     0.56855
 0.682146    0.285136   0.287865  0.97511    0.89489
 0.370766    0.569141   0.42673   0.917962   0.91706

julia> mask = iseven.(1:10)
10-element BitArray{1}:
 false
  true
 false
  true
 false
  true
 false
  true
 false
  true

julia> other = Array{Bool}(trues(5))
5-element Array{Bool,1}:
 true
 true
 true
 true
 true

julia> aa[mask, other']
ERROR: ArgumentError: index CartesianIndex{2}[CartesianIndex(1, 1), CartesianIndex(1, 2), CartesianIndex(1, 3), CartesianIndex(1, 4), CartesianIndex(1, 5)] not found
Stacktrace:
 [1] axisindexes at /Users/rory/.playground/share/simulation/depot/packages/AxisArrays/G6pZY/src/indexing.jl:302 [inlined]
 [2] axisindexes at /Users/rory/.playground/share/simulation/depot/packages/AxisArrays/G6pZY/src/indexing.jl:174 [inlined]
 [3] macro expansion at /Users/rory/.playground/share/simulation/depot/packages/AxisArrays/G6pZY/src/indexing.jl:354 [inlined]
 [4] to_index at /Users/rory/.playground/share/simulation/depot/packages/AxisArrays/G6pZY/src/indexing.jl:311 [inlined]
 [5] getindex at /Users/rory/.playground/share/simulation/depot/packages/AxisArrays/G6pZY/src/indexing.jl:117 [inlined] (repeats 2 times)
 [6] top-level scope at none:0