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
8 changes: 4 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ function recursivecopy!(
end

function recursivecopy!(b::AbstractVectorOfArray, a::AbstractVectorOfArray)
if ArrayInterface.ismutable(eltype(b.u))
@inbounds for i in eachindex(b.u, a.u)
@inbounds for i in eachindex(b.u, a.u)
if ArrayInterface.ismutable(b.u[i]) || b.u[i] isa AbstractVectorOfArray
recursivecopy!(b.u[i], a.u[i])
else
b.u[i] = recursivecopy(a.u[i])
end
else
copyto!(b.u, a.u)
end
return b
end
Expand Down
10 changes: 10 additions & 0 deletions test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ end
@test u1.u[2] == [2.0, 2.0]
@test u1.u[1] isa SVector
@test u1.u[2] isa SVector

# mixed/nested partition types create a Union eltype for `u`.
# recursivecopy! must not fall back to a shallow copy in this case.
a = VectorOfArray([ones(2), VectorOfArray([1.0, 1.0])])
b = recursivecopy(a)
recursivecopy!(b, a)
@test !(b.u[1] === a.u[1])
@test !(b.u[2] === a.u[2])
b.u[1][1] = 99.0
@test a.u[1][1] == 1.0
end

@testset "VectorOfArray similar with nested scalar leaves" begin
Expand Down
Loading