@@ -156,13 +156,16 @@ function VectorOfArray(vec::AbstractVector{VT}) where {T, N, VT <: AbstractArray
156156 VectorOfArray {T, N + 1, typeof(vec)} (vec)
157157end
158158
159- # allow multi-dimensional arrays as long as they're linearly indexed
159+ # allow multi-dimensional arrays as long as they're linearly indexed.
160+ # currently restricted to arrays whose elements are all the same type
160161function VectorOfArray (array:: AbstractArray{AT} ) where {T, N, AT <: AbstractArray{T, N} }
161162 @assert IndexStyle (typeof (array)) isa IndexLinear
162163
163164 return VectorOfArray {T, N + 1, typeof(array)} (array)
164165end
165166
167+ Base. parent (vec:: VectorOfArray ) = vec. u
168+
166169function DiffEqArray (vec:: AbstractVector{T} ,
167170 ts:: AbstractVector ,
168171 :: NTuple{N, Int} ,
721724 VectorOfArray ([similar (VA[:, i], T) for i in eachindex (VA. u)])
722725end
723726
727+ # for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type
728+ @inline function Base. similar (vec:: VectorOfArray{T, N, AT} ) where {T, N, AT <: AbstractArray{<:AbstractArray{T}} }
729+ return VectorOfArray (similar (Base. parent (vec)))
730+ end
731+
732+ # special-case when the multi-dimensional parent array is just an AbstractVector (call the old method)
733+ @inline function Base. similar (vec:: VectorOfArray{T, N, AT} ) where {T, N, AT <: AbstractVector{<:AbstractArray{T}} }
734+ return Base. similar (vec, eltype (vec))
735+ end
736+
724737# fill!
725738# For DiffEqArray it ignores ts and fills only u
726739function Base. fill! (VA:: AbstractVectorOfArray , x)
0 commit comments