Skip to content

Commit 2d4a88d

Browse files
committed
Fix TR scalars
1 parent 9c50e5f commit 2d4a88d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Diff for: src/default.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip},
127127
alg::FastShortcutNonlinearPolyalg, args...; kwargs...) where {uType, iip}
128128
@unpack adkwargs, linsolve, precs = alg
129129

130-
algs = (
131-
GeneralKlement(; linsolve, precs),
130+
algs = (GeneralKlement(; linsolve, precs),
132131
GeneralBroyden(),
133132
NewtonRaphson(; linsolve, precs, adkwargs...),
134133
NewtonRaphson(; linsolve, precs, linesearch = BackTracking(), adkwargs...),

Diff for: src/trustRegion.jl

+10-5
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,16 @@ function perform_step!(cache::TrustRegionCache{false})
388388
cache.g = _restructure(fu, J' * _vec(fu))
389389
cache.stats.njacs += 1
390390

391-
# do not use A = cache.H, b = _vec(cache.g) since it is equivalent
392-
# to A = cache.J, b = _vec(fu) as long as the Jacobian is non-singular
393-
linres = dolinsolve(cache.alg.precs, cache.linsolve, A = cache.J, b = -_vec(fu),
394-
linu = _vec(cache.u_gauss_newton), p = p, reltol = cache.abstol)
395-
cache.linsolve = linres.cache
391+
if cache.linsolve === nothing
392+
# Scalar
393+
cache.u_gauss_newton = cache.H \ cache.g
394+
else
395+
# do not use A = cache.H, b = _vec(cache.g) since it is equivalent
396+
# to A = cache.J, b = _vec(fu) as long as the Jacobian is non-singular
397+
linres = dolinsolve(cache.alg.precs, cache.linsolve, A = cache.J, b = -_vec(fu),
398+
linu = _vec(cache.u_gauss_newton), p = p, reltol = cache.abstol)
399+
cache.linsolve = linres.cache
400+
end
396401
end
397402

398403
# Compute the Newton step.

0 commit comments

Comments
 (0)