meggart / DiskArrays.jl

Other
79 stars 16 forks source link

`BoundsError` when extra-indexing with `AbstractVector` #97

Closed tcarion closed 1 year ago

tcarion commented 1 year ago

In regular Julia array, it is possible to index a N-dimensional array with more than N indices (see the documentation). When using an AbstractVector for additional indices, it fails with a DiskArray, which is inconsistent with the behaviour of Julia arrays:

Julia arrays:

julia> A = [8,6,7];
julia> A[2, [1]] # or A[2, 1:1]
1-element Vector{Int64}:
 6

_DiskArray from the tests:

julia> DA = _DiskArray(A);
julia> DA[2, [1]] # or DA[2, 1:1]
ERROR: BoundsError: attempt to access 3-element _DiskArray{Int64, 1, Vector{Int64}} at index [2, [1]]
Stacktrace:
 [1] #7
   @ ~/.julia/dev/DiskArrays/src/diskarray.jl:92 [inlined]
 [2] foreach
   @ ./abstractarray.jl:2712 [inlined]
 [3] interpret_indices_disk(A::_DiskArray{Int64, 1, Vector{Int64}}, r::Tuple{Int64, Vector{Int64}})
   @ DiskArrays ~/.julia/dev/DiskArrays/src/diskarray.jl:91
 [4] getindex_disk(::_DiskArray{Int64, 1, Vector{Int64}}, ::Int64, ::Vararg{Any})
   @ DiskArrays ~/.julia/dev/DiskArrays/src/diskarray.jl:29
 [5] getindex(::_DiskArray{Int64, 1, Vector{Int64}}, ::Int64, ::Vector{Int64})
   @ Main ~/.julia/dev/DiskArrays/src/diskarray.jl:178
 [6] top-level scope
   @ REPL[56]:1

Note that there's no issue when indexing with an integer (DA[2, 1] works fine)

This issue originated from here

cc @rafaqz

rafaqz commented 1 year ago

This is more something @meggart will know more about than me.

But I think there is already a mechanism for adding these dimensions, we just need to plug it in.

meggart commented 1 year ago

Yes, this is a case not yet covered by DiskArrays, will prepare a fix today.

rafaqz commented 1 year ago

@tcarion this is fixed with #98