Skip to content

Commit a39ec3f

Browse files
committed
Fix #98
1 parent b82c855 commit a39ec3f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/vector_of_array.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,26 @@ DiffEqArray(vec::AbstractVector{VT},ts::AbstractVector) where {T, N, VT<:Abstrac
3939
@inline Base.getindex(VA::AbstractVectorOfArray{T, N}, I::AbstractArray{Int}) where {T, N} = VectorOfArray(VA.u[I])
4040
@inline Base.getindex(VA::AbstractDiffEqArray{T, N}, I::AbstractArray{Int}) where {T, N} = DiffEqArray(VA.u[I],VA.t[I])
4141
@inline Base.getindex(VA::AbstractVectorOfArray{T, N}, i::Int,::Colon) where {T, N} = [VA.u[j][i] for j in 1:length(VA)]
42+
Base.@propagate_inbounds function Base.getindex(VA::AbstractVectorOfArray{T,N}, ii::CartesianIndex) where {T, N}
43+
ti = Tuple(ii)
44+
i = first(ti)
45+
jj = CartesianIndex(Base.tail(ti))
46+
return VA.u[i][jj]
47+
end
4248
@inline Base.setindex!(VA::AbstractVectorOfArray{T, N}, v, I::Int) where {T, N} = VA.u[I] = v
4349
@inline Base.setindex!(VA::AbstractVectorOfArray{T, N}, v, I::Colon) where {T, N} = VA.u[I] = v
4450
@inline Base.setindex!(VA::AbstractVectorOfArray{T, N}, v, I::AbstractArray{Int}) where {T, N} = VA.u[I] = v
4551
@inline function Base.setindex!(VA::AbstractVectorOfArray{T, N}, v, i::Int,::Colon) where {T, N}
4652
for j in 1:length(VA)
4753
VA.u[j][i] = v[j]
4854
end
55+
return v
56+
end
57+
Base.@propagate_inbounds function Base.setindex!(VA::AbstractVectorOfArray{T,N}, x, ii::CartesianIndex) where {T, N}
58+
ti = Tuple(ii)
59+
i = first(ti)
60+
jj = CartesianIndex(Base.tail(ti))
61+
return VA.u[i][jj] = x
4962
end
5063

5164
# Interface for the two dimensional indexing, a more standard AbstractArray interface

test/basic_indexing.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ a = testva .+ rand(3,3)
8080
recs = [rand(2,2) for i in 1:5]
8181
testva = VectorOfArray(recs)
8282
@test Array(testva) isa Array{Float64,3}
83+
84+
v = VectorOfArray([zeros(20), zeros(10,10), zeros(3,3,3)])
85+
v[CartesianIndex((3, 2, 3, 2))] = 1
86+
@test v[CartesianIndex((3, 2, 3, 2))] == 1
87+
@test v.u[3][2, 3, 2] == 1

0 commit comments

Comments
 (0)