Skip to content

Commit 672cd31

Browse files
committed
Use deepcopy to copy initial guess
1 parent b6f2999 commit 672cd31

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

lib/BoundaryValueDiffEqCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BoundaryValueDiffEqCore"
22
uuid = "56b672f2-a5fe-4263-ab2d-da677488eb3a"
3-
version = "2.2.0"
3+
version = "2.2.1"
44
authors = ["Qingyu Qu <erikqqy123@gmail.com>"]
55

66
[deps]

lib/BoundaryValueDiffEqCore/src/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,15 +617,15 @@ as the mesh of the `DiffEqArray`.
617617
end
618618
@inline function __initial_guess_on_mesh(u₀::VectorOfArray, mesh, p; tune_parameters = false)
619619
tune_parameters && return VectorOfArray([vcat(vec(u), __tunable_part(p)) for u in u₀.u])
620-
return copy(u₀)
620+
return deepcopy(u₀)
621621
end
622622
@inline function __initial_guess_on_mesh(u₀::DiffEqArray, mesh, p; tune_parameters = false)
623623
tune_parameters && return DiffEqArray([vcat(vec(u), __tunable_part(p)) for u in u₀.u])
624-
return copy(u₀)
624+
return deepcopy(u₀)
625625
end
626626
@inline function __initial_guess_on_mesh(u₀::SciMLBase.ODESolution, mesh, p; tune_parameters = false)
627627
tune_parameters && return VectorOfArray([vcat(vec(u), __tunable_part(p)) for u in u₀.u])
628-
return copy(VectorOfArray(u₀.u))
628+
return deepcopy(VectorOfArray(u₀.u))
629629
end
630630
@inline function __initial_guess_on_mesh(u₀::AbstractArray, mesh, p; tune_parameters = false)
631631
tune_parameters && return VectorOfArray([vcat(vec(u₀), __tunable_part(p)) for _ in mesh])

lib/BoundaryValueDiffEqFIRK/test/expanded/firk_basic_tests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,5 +566,9 @@ end
566566
bvp2 = TwoPointBVProblem(f!, (bca!, bcb!), sol1, tspan; bcresid_prototype = (zeros(2), zeros(1)))
567567
sol2 = solve(bvp2, LobattoIIIa3(), dt = 0.1, adaptive = false, nlsolve_kwargs = (; maxiters = 0))
568568
@test sol2.u == u_guess
569+
570+
# Ensure the initial guess is not modified in-place
571+
sol2 = solve(bvp2, LobattoIIIa3(), dt = 0.1, adaptive = false)
572+
@test bvp2.u0 == u_guess
569573
end
570574
=#

lib/BoundaryValueDiffEqFIRK/test/nested/firk_basic_tests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,4 +646,8 @@ end
646646
bvp2 = TwoPointBVProblem(f!, (bca!, bcb!), sol1, tspan; bcresid_prototype = (zeros(2), zeros(1)))
647647
sol2 = solve(bvp2, RadauIIa5(; nested_nlsolve = true), dt = 0.1, adaptive = false, nlsolve_kwargs = (; maxiters = 0))
648648
@test sol2.u == u_guess
649+
650+
# Ensure the initial guess is not modified in-place
651+
sol2 = solve(bvp2, RadauIIa5(; nested_nlsolve = true), dt = 0.1, adaptive = false)
652+
@test bvp2.u0 == u_guess
649653
end

lib/BoundaryValueDiffEqMIRK/test/mirk_basic_tests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,8 @@ end
686686
bvp2 = TwoPointBVProblem(f!, (bca!, bcb!), sol1, tspan; bcresid_prototype = (zeros(2), zeros(1)))
687687
sol2 = solve(bvp2, MIRK4(), dt = 0.1, adaptive = false, nlsolve_kwargs = (; maxiters = 0))
688688
@test sol2.u == u_guess
689+
690+
# Ensure the initial guess is not modified in-place
691+
sol2 = solve(bvp2, MIRK4(), dt = 0.1, adaptive = false)
692+
@test bvp2.u0 == u_guess
689693
end

0 commit comments

Comments
 (0)