File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -1404,7 +1404,11 @@ function Base.similar(
14041404end
14051405
14061406@inline function Base. similar (VA:: VectorOfArray , :: Type{T} = eltype (VA)) where {T}
1407- return VectorOfArray (similar .(VA. u, T))
1407+ if eltype (VA. u) <: Union{AbstractArray, AbstractVectorOfArray}
1408+ return VectorOfArray (similar .(VA. u, T))
1409+ else
1410+ return VectorOfArray (similar (VA. u, T))
1411+ end
14081412end
14091413
14101414@inline function Base. similar (VA:: VectorOfArray , dims:: N ) where {N <: Number }
@@ -1420,7 +1424,7 @@ end
14201424# For DiffEqArray it ignores ts and fills only u
14211425function Base. fill! (VA:: AbstractVectorOfArray , x)
14221426 for i in 1 : length (VA. u)
1423- if VA[:, i] isa AbstractArray
1427+ if VA[:, i] isa Union{ AbstractArray, AbstractVectorOfArray}
14241428 if ArrayInterface. ismutable (VA. u[i]) || VA. u[i] isa AbstractVectorOfArray
14251429 fill! (VA[:, i], x)
14261430 else
Original file line number Diff line number Diff line change 151151 @test a. u[1 ][1 ] == 1.0
152152end
153153
154+ @testset " VectorOfArray similar with nested scalar leaves" begin
155+ a = VectorOfArray ([ones (2 ), VectorOfArray ([1.0 , 1.0 ])])
156+ b = similar (a, Float64)
157+ @test b isa typeof (a)
158+ @test b. u[1 ] isa Vector{Float64}
159+ @test b. u[2 ] isa typeof (a. u[2 ])
160+ @test b. u[2 ]. u isa Vector{Float64}
161+ @test length (b. u[2 ]. u) == 2
162+ end
163+
164+ @testset " recursivefill! with nested union partitions" begin
165+ a = VectorOfArray ([ones (2 ), VectorOfArray ([1.0 , 1.0 ])])
166+ recursivefill! (a, true )
167+ @test a. u[1 ] == ones (2 )
168+ @test a. u[2 ]. u == ones (2 )
169+ end
170+
154171# Test recursivefill! with immutable StaticArrays (issue #461)
155172@testset " recursivefill! with immutable StaticArrays (issue #461)" begin
156173 # Test with only immutable SVectors
You can’t perform that action at this time.
0 commit comments