Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/interface_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)