@@ -160,6 +160,24 @@ function DiffEqArray(vec::AbstractVector{T},
160160 p,
161161 sys)
162162end
163+
164+ # ambiguity resolution
165+ function DiffEqArray (vec:: AbstractVector{VT} ,
166+ ts:: AbstractVector ,
167+ :: NTuple{N, Int} ) where {T, N, VT <: AbstractArray{T, N} }
168+ DiffEqArray {eltype(T), N, typeof(vec), typeof(ts), Nothing, Nothing} (vec,
169+ ts,
170+ nothing ,
171+ nothing )
172+ end
173+ function DiffEqArray (vec:: AbstractVector{VT} ,
174+ ts:: AbstractVector ,
175+ :: NTuple{N, Int} , p) where {T, N, VT <: AbstractArray{T, N} }
176+ DiffEqArray {eltype(T), N, typeof(vec), typeof(ts), typeof(p), Nothing} (vec,
177+ ts,
178+ p,
179+ nothing )
180+ end
163181# Assume that the first element is representative of all other elements
164182
165183function DiffEqArray (vec:: AbstractVector ,
@@ -174,9 +192,10 @@ function DiffEqArray(vec::AbstractVector,
174192 something (parameters, []),
175193 something (independent_variables, [])))
176194 _size = size (vec[1 ])
195+ T = eltype (vec[1 ])
177196 return DiffEqArray{
178- eltype ( eltype (vec)) ,
179- length (_size),
197+ T ,
198+ length (_size) + 1 ,
180199 typeof (vec),
181200 typeof (ts),
182201 typeof (p),
@@ -466,19 +485,25 @@ end
466485tuples (VA:: DiffEqArray ) = tuple .(VA. t, VA. u)
467486
468487# Growing the array simply adds to the container vector
469- function Base. copy (VA:: AbstractDiffEqArray )
470- typeof (VA)(copy (VA. u),
471- copy (VA. t),
472- (VA. p === nothing ) ? nothing : copy (VA. p),
473- (VA. sys === nothing ) ? nothing : copy (VA. sys))
488+ function _copyfield (VA, fname)
489+ if fname == :u
490+ copy (VA. u)
491+ elseif fname == :t
492+ copy (VA. t)
493+ else
494+ getfield (VA, fname)
495+ end
496+ end
497+ function Base. copy (VA:: AbstractVectorOfArray )
498+ typeof (VA)((_copyfield (VA, fname) for fname in fieldnames (typeof (VA))). .. )
474499end
475- Base. copy (VA:: AbstractVectorOfArray ) = typeof (VA)(copy (VA. u))
476-
477- Base. zero (VA:: AbstractVectorOfArray ) = VectorOfArray (Base. zero .(VA. u))
478500
479- function Base. zero (VA:: AbstractDiffEqArray )
480- u = Base. zero .(VA. u)
481- DiffEqArray (u, VA. t, parameter_values (VA), symbolic_container (VA))
501+ function Base. zero (VA:: AbstractVectorOfArray )
502+ val = copy (VA)
503+ for i in eachindex (VA. u)
504+ val. u[i] = zero (VA. u[i])
505+ end
506+ return val
482507end
483508
484509Base. sizehint! (VA:: AbstractVectorOfArray{T, N} , i) where {T, N} = sizehint! (VA. u, i)
563588function Base. copyto! (dest:: AbstractVectorOfArray{T,N} , src:: AbstractVectorOfArray{T,N} ) where {T,N}
564589 copyto! .(dest. u, src. u)
565590end
591+ function Base. copyto! (dest:: AbstractVectorOfArray{T, N} , src:: AbstractArray{T, N} ) where {T, N}
592+ for (i, slice) in enumerate (eachslice (src, dims = ndims (src)))
593+ copyto! (dest. u[i], slice)
594+ end
595+ dest
596+ end
597+ function Base. copyto! (dest:: AbstractVectorOfArray{T, N, <:AbstractVector{T}} , src:: AbstractVector{T} ) where {T, N}
598+ copyto! (dest. u, src)
599+ dest
600+ end
566601# Required for broadcasted setindex! when slicing across subarrays
567602# E.g. if `va = VectorOfArray([rand(3, 3) for i in 1:5])`
568603# Need this method for `va[2, :, :] .= 3.0`
0 commit comments