Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-rs committed Apr 23, 2023
1 parent 3cee23b commit 99fc63f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/trustRegion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
max_trust_radius, step_threshold, shrink_threshold,
expand_threshold, shrink_factor, expand_factor, loss,
loss_new, H, g, shrink_counter, step_size, u_tmp, fu_new,
make_new_J, r, p1, p2, p3, p4, ϵ, iter_arr)
make_new_J, r, p1, p2, p3, p4, ϵ)
end

function perform_step!(cache::TrustRegionCache{true})
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

0 comments on commit 99fc63f

Please sign in to comment.