Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Nov 24, 2022
1 parent f079e69 commit 79ac0fb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
7 changes: 3 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ allow for automatically generating high-performance code.

Performance is key: the current methods are made to be highly performant on
scalar and statically sized small problems, with options for large-scale systems.
If you run into any performance issues, please file an issue. Note that this
package is distinct from [SciMLNLSolve.jl](https://github.com/SciML/SciMLNLSolve.jl).
If you run into any performance issues, please file an issue.
Consult the [NonlinearSystemSolvers](@ref nonlinearsystemsolvers) page for
information on how to import solvers from different packages.

Expand Down Expand Up @@ -79,7 +78,7 @@ Pkg.status(;mode = PKGMODE_MANIFEST) # hide
</details>
```
```@raw html
You can also download the
You can also download the
<a href="
```
```@eval
Expand All @@ -100,4 +99,4 @@ link = "https://github.com/SciML/"*name*".jl/tree/gh-pages/v"*version*"/assets/P
```
```@raw html
">project</a> file.
```
```
3 changes: 2 additions & 1 deletion src/jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function jacobian(f, x::Number, solver)
if alg_autodiff(solver.alg)
J = ForwardDiff.derivative(f, x)
else
J = FiniteDiff.finite_difference_derivative(f, x, alg_difftype(solver.alg), eltype(x))
J = FiniteDiff.finite_difference_derivative(f, x, alg_difftype(solver.alg),
eltype(x))
end
return J
end
Expand Down
37 changes: 20 additions & 17 deletions src/raphson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function NewtonRaphson(; chunk_size = Val{0}(), autodiff = Val{true}(),
_unwrap_val(concrete_jac)}(linsolve, precs)
end

mutable struct NewtonRaphsonCache{iip, fType, algType, uType, duType, resType, pType, INType, tolType,
mutable struct NewtonRaphsonCache{iip, fType, algType, uType, duType, resType, pType,
INType, tolType,
probType, ufType, L, jType, JC}
f::fType
alg::algType
Expand All @@ -32,22 +33,25 @@ mutable struct NewtonRaphsonCache{iip, fType, algType, uType, duType, resType, p
abstol::tolType
prob::probType

function NewtonRaphsonCache{iip}(f::fType, alg::algType, u::uType, fu::resType, p::pType,
uf::ufType, linsolve::L, J::jType, du1::duType, jac_config::JC, iter::Int,
force_stop::Bool, maxiters::Int, internalnorm::INType,
retcode::SciMLBase.ReturnCode.T, abstol::tolType, prob::probType) where {
iip, fType, algType, uType, duType, resType, pType, INType, tolType,
probType, ufType, L, jType, JC}
function NewtonRaphsonCache{iip}(f::fType, alg::algType, u::uType, fu::resType,
p::pType,
uf::ufType, linsolve::L, J::jType, du1::duType,
jac_config::JC, iter::Int,
force_stop::Bool, maxiters::Int, internalnorm::INType,
retcode::SciMLBase.ReturnCode.T, abstol::tolType,
prob::probType) where {
iip, fType, algType, uType,
duType, resType, pType, INType,
tolType,
probType, ufType, L, jType, JC}
new{iip, fType, algType, uType, duType, resType, pType, INType, tolType,
probType, ufType, L, jType, JC}(f, alg, u, fu, p,
uf, linsolve, J, du1, jac_config, iter,
force_stop, maxiters, internalnorm,
retcode, abstol, prob)
probType, ufType, L, jType, JC}(f, alg, u, fu, p,
uf, linsolve, J, du1, jac_config, iter,
force_stop, maxiters, internalnorm,
retcode, abstol, prob)
end

end


function jacobian_caches(alg::NewtonRaphson, f, u, p, ::Val{true})
uf = JacobianWrapper(f, p)
J = false .* u .* u'
Expand Down Expand Up @@ -105,8 +109,8 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::NewtonRaphson
uf, linsolve, J, du1, jac_config = jacobian_caches(alg, f, u, p, Val(iip))

return NewtonRaphsonCache{iip}(f, alg, u, fu, p, uf, linsolve, J, du1, jac_config,
1, false, maxiters, internalnorm,
ReturnCode.Default, abstol, prob)
1, false, maxiters, internalnorm,
ReturnCode.Default, abstol, prob)
end

function perform_step!(cache::NewtonRaphsonCache{true})
Expand Down Expand Up @@ -139,7 +143,6 @@ function perform_step!(cache::NewtonRaphsonCache{false})
end

function SciMLBase.solve!(cache::NewtonRaphsonCache)

while !cache.force_stop && cache.iter < cache.maxiters
perform_step!(cache)
cache.iter += 1
Expand All @@ -150,5 +153,5 @@ function SciMLBase.solve!(cache::NewtonRaphsonCache)
end

SciMLBase.build_solution(cache.prob, cache.alg, cache.u, cache.fu;
retcode = cache.retcode)
retcode = cache.retcode)
end
5 changes: 2 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ _vec(v) = vec(v)
_vec(v::Number) = v
_vec(v::AbstractVector) = v


function alg_difftype(alg::AbstractNewtonAlgorithm{CS, AD, FDT, ST, CJ}
) where {CS, AD, FDT, ST, CJ}
function alg_difftype(alg::AbstractNewtonAlgorithm{CS, AD, FDT, ST, CJ}) where {CS, AD, FDT,
ST, CJ}
FDT
end

Expand Down
2 changes: 1 addition & 1 deletion test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ f, u0 = (u, p) -> u * u - p, 1.0
# NewtonRaphson
g = function (p)
probN = NonlinearProblem{false}(f, oftype(p, u0), p)
sol = solve(probN, NewtonRaphson(), abstol=1e-10)
sol = solve(probN, NewtonRaphson(), abstol = 1e-10)
return sol.u
end

Expand Down

0 comments on commit 79ac0fb

Please sign in to comment.