Skip to content

Commit 99fc63f

Browse files
committed
added test
1 parent 3cee23b commit 99fc63f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/trustRegion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
331331
max_trust_radius, step_threshold, shrink_threshold,
332332
expand_threshold, shrink_factor, expand_factor, loss,
333333
loss_new, H, g, shrink_counter, step_size, u_tmp, fu_new,
334-
make_new_J, r, p1, p2, p3, p4, ϵ, iter_arr)
334+
make_new_J, r, p1, p2, p3, p4, ϵ)
335335
end
336336

337337
function perform_step!(cache::TrustRegionCache{true})

test/basictests.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,42 @@ for options in list_of_options
486486
@test all(abs.(f(u, p)) .< 1e-10)
487487
end
488488

489+
# Testing consistency of iip vs oop iterations
490+
491+
maxiterations = [2, 3, 4, 5]
492+
u0 = [1.0, 1.0]
493+
function iip_oop(f, fip, u0, radius_update_scheme, maxiters)
494+
prob_iip = NonlinearProblem{true}(fip, u0)
495+
solver = init(prob_iip, TrustRegion(radius_update_scheme = radius_update_scheme), abstol = 1e-9, maxiters = maxiters)
496+
sol_iip = solve!(solver)
497+
498+
prob_oop = NonlinearProblem{false}(f, u0)
499+
solver = init(prob_oop, TrustRegion(radius_update_scheme = radius_update_scheme), abstol = 1e-9, maxiters = maxiters)
500+
sol_oop = solve!(solver)
501+
502+
return sol_iip.u[end], sol_oop.u[end]
503+
end
504+
505+
for maxiters in maxiterations
506+
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Simple, maxiters)
507+
@test iip == oop
508+
end
509+
510+
for maxiters in maxiterations
511+
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Hei, maxiters)
512+
@test iip == oop
513+
end
514+
515+
for maxiters in maxiterations
516+
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Yuan, maxiters)
517+
@test iip == oop
518+
end
519+
520+
for maxiters in maxiterations
521+
iip, oop = iip_oop(ff, ffiip, u0, RadiusUpdateSchemes.Fan, maxiters)
522+
@test iip == oop
523+
end
524+
489525
# --- LevenbergMarquardt tests ---
490526

491527
function benchmark_immutable(f, u0)

0 commit comments

Comments
 (0)