jonniedie / ComponentArrays.jl

Arrays with arbitrarily nested named components.
MIT License
287 stars 34 forks source link

Compatibility with OffsetArrays #178

Open rs1909 opened 1 year ago

rs1909 commented 1 year ago

I can put OffsetArrays into a ComponentArray, but the offsets are not preserved:

using ComponentArrays, OffsetArrays
B = OffsetArray(randn(6,6), 0:5, 0:5)
C = OffsetArray(randn(6,6), 0:5, 0:5)
V = ComponentArray(b=B, c=C)

B[0,0] # works
V.b[0,0] # ERROR: BoundsError:
jonniedie commented 1 year ago

Unfortunately this one is kinda on OffsetArrays for not returning an OffsetArray when indexing.

julia> oa = OffsetArray([1, 2, 3, 4], -1)
4-element OffsetArray(::Vector{Int64}, 0:3) with eltype Int64 with indices 0:3:
 1
 2
 3
 4

julia> b = oa[0:2]
3-element Vector{Int64}:
 1
 2
 3

julia> b[0]
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [0]
Stacktrace:
 [1] getindex(A::Vector{Int64}, i1::Int64)
   @ Base ./array.jl:924
 [2] top-level scope
   @ REPL[15]:1

There's nothing we could really do other than make OffsetArrays a dependency and maintain methods specifically for it.

CarloLucibello commented 1 year ago

An OffsetArrays extension would be nice