Skip to content

Commit 06c8004

Browse files
add setindex! operations
1 parent c049fc3 commit 06c8004

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/vector_of_array.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ DiffEqArray(vec::AbstractVector,ts::AbstractVector) = DiffEqArray(vec, ts, (size
2727
@inline Base.getindex{T, N}(VA::AbstractVectorOfArray{T, N}, I::Colon) = VA.u[I]
2828
@inline Base.getindex{T, N}(VA::AbstractVectorOfArray{T, N}, I::AbstractArray{Int}) = VA.u[I]
2929
@inline Base.getindex{T, N}(VA::AbstractVectorOfArray{T, N}, i::Int,::Colon) = [VA.u[j][i] for j in 1:length(VA)]
30+
@inline Base.setindex!{T, N}(VA::AbstractVectorOfArray{T, N}, v, I::Int) = VA.u[I] = v
31+
@inline Base.setindex!{T, N}(VA::AbstractVectorOfArray{T, N}, v, I::Colon) = VA.u[I] = v
32+
@inline Base.setindex!{T, N}(VA::AbstractVectorOfArray{T, N}, v, I::AbstractArray{Int}) = VA.u[I] = v
33+
@inline function Base.setindex!{T, N}(VA::AbstractVectorOfArray{T, N}, v, i::Int,::Colon)
34+
for j in 1:length(VA)
35+
VA.u[j][i] = v[j]
36+
end
37+
end
3038

3139
# Interface for the two dimensional indexing, a more standard AbstractArray interface
3240
@inline Base.size(VA::AbstractVectorOfArray) = (size(VA.u[1])..., length(VA.u))
3341
@inline Base.getindex{T, N}(VA::AbstractVectorOfArray{T, N}, I::Int...) = VA.u[I[end]][Base.front(I)...]
42+
@inline Base.setindex!{T, N}(VA::AbstractVectorOfArray{T, N}, v, I::Int...) = VA.u[I[end]][Base.front(I)...] = v
3443

3544
# The iterator will be over the subarrays of the container, not the individual elements
3645
# unlike an true AbstractArray

0 commit comments

Comments
 (0)