diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index a043ea50..f269da94 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -426,12 +426,34 @@ function Base.copy(VA::AbstractDiffEqArray) (VA.sys === nothing) ? nothing : copy(VA.sys)) end Base.copy(VA::AbstractVectorOfArray) = typeof(VA)(copy(VA.u)) + +Base.zero(VA::VectorOfArray) = VectorOfArray(Base.zero.(VA.u)) + +function Base.zero(VA::DiffEqArray) + u = Base.zero.(VA.u) + DiffEqArray(u, VA.t, VA.p, VA.sys) +end + Base.sizehint!(VA::AbstractVectorOfArray{T, N}, i) where {T, N} = sizehint!(VA.u, i) Base.reverse!(VA::AbstractVectorOfArray) = reverse!(VA.u) Base.reverse(VA::VectorOfArray) = VectorOfArray(reverse(VA.u)) Base.reverse(VA::DiffEqArray) = DiffEqArray(reverse(VA.u), VA.t, VA.p, VA.sys) +function Base.resize!(VA::AbstractVectorOfArray, i::Integer) + if Base.hasproperty(VA, :sys) && VA.sys !== nothing + error("resize! is not allowed on AbstractVectorOfArray with a sys") + end + Base.resize!(VA.u, i) + if Base.hasproperty(VA, :t) && VA.t !== nothing + Base.resize!(VA.t, i) + end +end + +function Base.pointer(VA::AbstractVectorOfArray) + Base.pointer(VA.u) +end + function Base.push!(VA::AbstractVectorOfArray{T, N}, new_item::AbstractArray) where {T, N} push!(VA.u, new_item) end diff --git a/test/interface_tests.jl b/test/interface_tests.jl index f87bb5dd..d29d1770 100644 --- a/test/interface_tests.jl +++ b/test/interface_tests.jl @@ -112,3 +112,8 @@ A = VectorOfArray(map(i -> rand(2, 4), 1:7)) DA = DiffEqArray(map(i -> rand(2, 4), 1:7), 1:7) @test map(x -> maximum(x), DA) isa Vector + +u = VectorOfArray([fill(2, SVector{2, Float64}), ones(SVector{2, Float64})]) +@test typeof(zero(u)) <: typeof(u) +resize!(u,3) +@test pointer(u) === pointer(u.u)