Skip to content

Commit

Permalink
Fix TR scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 27, 2023
1 parent 9c50e5f commit 2d4a88d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip},
alg::FastShortcutNonlinearPolyalg, args...; kwargs...) where {uType, iip}
@unpack adkwargs, linsolve, precs = alg

algs = (
GeneralKlement(; linsolve, precs),
algs = (GeneralKlement(; linsolve, precs),

Check warning on line 130 in src/default.jl

View check run for this annotation

Codecov / codecov/patch

src/default.jl#L130

Added line #L130 was not covered by tests
GeneralBroyden(),
NewtonRaphson(; linsolve, precs, adkwargs...),
NewtonRaphson(; linsolve, precs, linesearch = BackTracking(), adkwargs...),
Expand Down
15 changes: 10 additions & 5 deletions src/trustRegion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,16 @@ function perform_step!(cache::TrustRegionCache{false})
cache.g = _restructure(fu, J' * _vec(fu))
cache.stats.njacs += 1

# do not use A = cache.H, b = _vec(cache.g) since it is equivalent
# to A = cache.J, b = _vec(fu) as long as the Jacobian is non-singular
linres = dolinsolve(cache.alg.precs, cache.linsolve, A = cache.J, b = -_vec(fu),
linu = _vec(cache.u_gauss_newton), p = p, reltol = cache.abstol)
cache.linsolve = linres.cache
if cache.linsolve === nothing
# Scalar
cache.u_gauss_newton = cache.H \ cache.g
else
# do not use A = cache.H, b = _vec(cache.g) since it is equivalent
# to A = cache.J, b = _vec(fu) as long as the Jacobian is non-singular
linres = dolinsolve(cache.alg.precs, cache.linsolve, A = cache.J, b = -_vec(fu),
linu = _vec(cache.u_gauss_newton), p = p, reltol = cache.abstol)
cache.linsolve = linres.cache
end
end

# Compute the Newton step.
Expand Down

0 comments on commit 2d4a88d

Please sign in to comment.