Skip to content

Commit afa4a80

Browse files
Merge pull request #302 from SciML/interface_funcs
Add and test some missing interface functions
2 parents 1501f08 + eece374 commit afa4a80

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/vector_of_array.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,34 @@ function Base.copy(VA::AbstractDiffEqArray)
426426
(VA.sys === nothing) ? nothing : copy(VA.sys))
427427
end
428428
Base.copy(VA::AbstractVectorOfArray) = typeof(VA)(copy(VA.u))
429+
430+
Base.zero(VA::VectorOfArray) = VectorOfArray(Base.zero.(VA.u))
431+
432+
function Base.zero(VA::DiffEqArray)
433+
u = Base.zero.(VA.u)
434+
DiffEqArray(u, VA.t, VA.p, VA.sys)
435+
end
436+
429437
Base.sizehint!(VA::AbstractVectorOfArray{T, N}, i) where {T, N} = sizehint!(VA.u, i)
430438

431439
Base.reverse!(VA::AbstractVectorOfArray) = reverse!(VA.u)
432440
Base.reverse(VA::VectorOfArray) = VectorOfArray(reverse(VA.u))
433441
Base.reverse(VA::DiffEqArray) = DiffEqArray(reverse(VA.u), VA.t, VA.p, VA.sys)
434442

443+
function Base.resize!(VA::AbstractVectorOfArray, i::Integer)
444+
if Base.hasproperty(VA, :sys) && VA.sys !== nothing
445+
error("resize! is not allowed on AbstractVectorOfArray with a sys")
446+
end
447+
Base.resize!(VA.u, i)
448+
if Base.hasproperty(VA, :t) && VA.t !== nothing
449+
Base.resize!(VA.t, i)
450+
end
451+
end
452+
453+
function Base.pointer(VA::AbstractVectorOfArray)
454+
Base.pointer(VA.u)
455+
end
456+
435457
function Base.push!(VA::AbstractVectorOfArray{T, N}, new_item::AbstractArray) where {T, N}
436458
push!(VA.u, new_item)
437459
end

test/interface_tests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,8 @@ A = VectorOfArray(map(i -> rand(2, 4), 1:7))
112112

113113
DA = DiffEqArray(map(i -> rand(2, 4), 1:7), 1:7)
114114
@test map(x -> maximum(x), DA) isa Vector
115+
116+
u = VectorOfArray([fill(2, SVector{2, Float64}), ones(SVector{2, Float64})])
117+
@test typeof(zero(u)) <: typeof(u)
118+
resize!(u,3)
119+
@test pointer(u) === pointer(u.u)

0 commit comments

Comments
 (0)