Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iip vs oop iteration test #179

Merged
merged 3 commits into from
Apr 23, 2023
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
1 change: 1 addition & 0 deletions src/trustRegion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
initial_trust_radius = convert(eltype(u), p1 * (norm(fu)^0.99))
end


return TrustRegionCache{iip}(f, alg, u, fu, p, uf, linsolve, J, jac_config,
1, false, maxiters, internalnorm,
ReturnCode.Default, abstol, prob, radius_update_scheme, initial_trust_radius,
Expand Down
36 changes: 36 additions & 0 deletions test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,42 @@ for options in list_of_options
@test all(abs.(f(u, p)) .< 1e-10)
end

# Testing consistency of iip vs oop iterations

maxiterations = [2, 3, 4, 5]
u0 = [1.0, 1.0]
function iip_oop(f, fip, u0, radius_update_scheme, maxiters)
prob_iip = NonlinearProblem{true}(fip, u0)
solver = init(prob_iip, TrustRegion(radius_update_scheme = radius_update_scheme), abstol = 1e-9, maxiters = maxiters)
sol_iip = solve!(solver)

prob_oop = NonlinearProblem{false}(f, u0)
solver = init(prob_oop, TrustRegion(radius_update_scheme = radius_update_scheme), abstol = 1e-9, maxiters = maxiters)
sol_oop = solve!(solver)

return sol_iip.u[end], sol_oop.u[end]
end

for maxiters in maxiterations
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Simple, maxiters)
@test iip == oop
end

for maxiters in maxiterations
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Hei, maxiters)
@test iip == oop
end

for maxiters in maxiterations
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Yuan, maxiters)
@test iip == oop
end

for maxiters in maxiterations
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Fan, maxiters)
@test iip == oop
end

# --- LevenbergMarquardt tests ---

function benchmark_immutable(f, u0)
Expand Down