From 518747a79c0a00dfea1dd3c7dbb88558f3b5ca5f Mon Sep 17 00:00:00 2001 From: Simon Carlson Date: Sun, 22 Jan 2023 18:57:24 +0100 Subject: [PATCH] Fixing load time for TrustRegion --- src/NonlinearSolve.jl | 2 +- src/trustRegion.jl | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/NonlinearSolve.jl b/src/NonlinearSolve.jl index b645df86d..79e6788c6 100644 --- a/src/NonlinearSolve.jl +++ b/src/NonlinearSolve.jl @@ -41,7 +41,7 @@ SnoopPrecompile.@precompile_all_calls begin for T in (Float32, Float64) prob = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2)) precompile_algs = if VERSION >= v"1.7" - (NewtonRaphson(),) + (NewtonRaphson(), TrustRegion(), LevenbergMarquardt()) else (NewtonRaphson(),) end diff --git a/src/trustRegion.jl b/src/trustRegion.jl index 1eeddc1d7..8294da579 100644 --- a/src/trustRegion.jl +++ b/src/trustRegion.jl @@ -232,19 +232,27 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion, max_trust_radius = alg.max_trust_radius initial_trust_radius = alg.initial_trust_radius if max_trust_radius == 0.0 - max_trust_radius = max(norm(fu), maximum(u) - minimum(u)) + max_trust_radius = convert(typeof(max_trust_radius), + max(norm(fu), maximum(u) - minimum(u))) end if initial_trust_radius == 0.0 initial_trust_radius = max_trust_radius / 11 end + + loss_new = loss H = ArrayInterfaceCore.undefmatrix(u) + g = zero(fu) + shrink_counter = 0 + step_size = zero(u) + fu_new = zero(fu) + make_new_J = true + r = loss return TrustRegionCache{iip}(f, alg, u, fu, p, uf, linsolve, J, jac_config, 1, false, maxiters, internalnorm, ReturnCode.Default, abstol, prob, initial_trust_radius, - max_trust_radius, loss, loss, H, zero(fu), 0, zero(u), - u_tmp, zero(fu), true, - loss) + max_trust_radius, loss, loss_new, H, g, shrink_counter, + step_size, u_tmp, fu_new, make_new_J, r) end function perform_step!(cache::TrustRegionCache{true}) @@ -293,7 +301,7 @@ function perform_step!(cache::TrustRegionCache{false}) end function trust_region_step!(cache::TrustRegionCache) - @unpack fu_new, u_tmp, step_size, g, H, loss, alg, max_trust_r = cache + @unpack fu_new, step_size, g, H, loss, alg, max_trust_r = cache cache.loss_new = get_loss(fu_new) # Compute the ratio of the actual reduction to the predicted reduction.