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

Support logical linear indexing #110

Closed iamed2 closed 7 years ago

iamed2 commented 7 years ago

Currently:

julia> input = AxisArray(collect(reshape(1:60, 12, 5)), .1:.1:1.2, [:a, :b, :c, :d, :e])
2-dimensional AxisArray{Int64,2,...} with axes:
    :row, 0.1:0.1:1.2
    :col, Symbol[:a, :b, :c, :d, :e]
And data, a 12×5 Array{Int64,2}:
  1  13  25  37  49
  2  14  26  38  50
  3  15  27  39  51
  4  16  28  40  52
  5  17  29  41  53
  6  18  30  42  54
  7  19  31  43  55
  8  20  32  44  56
  9  21  33  45  57
 10  22  34  46  58
 11  23  35  47  59
 12  24  36  48  60

julia> input[find(isfinite.(input))]
1-dimensional AxisArray{Int64,1,...} with axes:
    :col, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10  …  51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
And data, a 60-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
  ⋮
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60

julia> input[isfinite.(input)]
ERROR: BoundsError: attempt to access 12×5 Array{Int64,2} at index [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10  …  51, 52, 53, 54, 55, 56, 57, 58, 59, 60], Base.Slice(Base.OneTo(5))]
Stacktrace:
 [1] throw_boundserror(::Array{Int64,2}, ::Tuple{Array{Int64,1},Base.Slice{Base.OneTo{Int64}}}) at ./abstractarray.jl:433
 [2] checkbounds at ./abstractarray.jl:362 [inlined]
 [3] macro expansion at ./multidimensional.jl:441 [inlined]
 [4] _getindex at ./multidimensional.jl:438 [inlined]
 [5] getindex at ./abstractarray.jl:882 [inlined]
 [6] getindex at /Users/ericdavies/.julia/v0.6/AxisArrays/src/indexing.jl:88 [inlined]
 [7] getindex(::AxisArrays.AxisArray{Int64,2,Array{Int64,2},Tuple{AxisArrays.Axis{:row,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}},AxisArrays.Axis{:col,Array{Symbol,1}}}}, ::BitArray{2}) at /Users/ericdavies/.julia/v0.6/AxisArrays/src/indexing.jl:99

IMO these should have identical results. I'll work on this unless there are any concerns.