@@ -3,22 +3,23 @@ module SimpleNonlinearSolve
33import PrecompileTools: @compile_workload , @setup_workload , @recompile_invalidations
44
55@recompile_invalidations begin
6- using ADTypes, ArrayInterface, ConcreteStructs, DiffEqBase, FastClosures, FiniteDiff,
7- ForwardDiff, Reexport, LinearAlgebra, SciMLBase
8-
9- import DiffEqBase: AbstractNonlinearTerminationMode,
10- AbstractSafeNonlinearTerminationMode,
11- AbstractSafeBestNonlinearTerminationMode,
12- NonlinearSafeTerminationReturnCode, get_termination_mode,
13- NONLINEARSOLVE_DEFAULT_NORM
6+ using ADTypes, ArrayInterface, FiniteDiff, ForwardDiff, NonlinearSolveBase, Reexport,
7+ LinearAlgebra, SciMLBase
8+
9+ import ConcreteStructs: @concrete
1410 import DiffResults
11+ import FastClosures: @closure
1512 import ForwardDiff: Dual
1613 import MaybeInplace: @bb , setindex_trait, CanSetindex, CannotSetindex
14+ import NonlinearSolveBase: AbstractNonlinearTerminationMode,
15+ AbstractSafeNonlinearTerminationMode,
16+ AbstractSafeBestNonlinearTerminationMode,
17+ get_termination_mode, NONLINEARSOLVE_DEFAULT_NORM
1718 import SciMLBase: AbstractNonlinearAlgorithm, build_solution, isinplace, _unwrap_val
1819 import StaticArraysCore: StaticArray, SVector, SMatrix, SArray, MArray, MMatrix, Size
1920end
2021
21- @reexport using ADTypes, SciMLBase
22+ @reexport using ADTypes, SciMLBase # TODO : Reexport NonlinearSolveBase after the situation with NonlinearSolve.jl is resolved
2223
2324abstract type AbstractSimpleNonlinearSolveAlgorithm <: AbstractNonlinearAlgorithm end
2425abstract type AbstractBracketingAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end
@@ -58,23 +59,28 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing, args...;
5859end
5960
6061# By Pass the highlevel checks for NonlinearProblem for Simple Algorithms
61- function SciMLBase. solve (
62- prob:: NonlinearProblem , alg:: AbstractSimpleNonlinearSolveAlgorithm ,
63- args... ; sensealg = nothing , u0 = nothing , p = nothing , kwargs... )
64- if sensealg === nothing && haskey (prob. kwargs, :sensealg )
65- sensealg = prob. kwargs[:sensealg ]
66- end
67- new_u0 = u0 != = nothing ? u0 : prob. u0
68- new_p = p != = nothing ? p : prob. p
69- return __internal_solve_up (
70- prob, sensealg, new_u0, u0 === nothing , new_p, p === nothing ,
71- alg, args... ; prob. kwargs... , kwargs... )
72- end
62+ # Using eval to prevent ambiguity
63+ for pType in (NonlinearProblem, NonlinearLeastSquaresProblem)
64+ @eval begin
65+ function SciMLBase. solve (
66+ prob:: $ (pType), alg:: AbstractSimpleNonlinearSolveAlgorithm , args... ;
67+ sensealg = nothing , u0 = nothing , p = nothing , kwargs... )
68+ if sensealg === nothing && haskey (prob. kwargs, :sensealg )
69+ sensealg = prob. kwargs[:sensealg ]
70+ end
71+ new_u0 = u0 != = nothing ? u0 : prob. u0
72+ new_p = p != = nothing ? p : prob. p
73+ return __internal_solve_up (
74+ prob, sensealg, new_u0, u0 === nothing , new_p, p === nothing ,
75+ alg, args... ; prob. kwargs... , kwargs... )
76+ end
7377
74- function __internal_solve_up (_prob:: NonlinearProblem , sensealg, u0, u0_changed, p,
75- p_changed, alg:: AbstractSimpleNonlinearSolveAlgorithm , args... ; kwargs... )
76- prob = u0_changed || p_changed ? remake (_prob; u0, p) : _prob
77- return SciMLBase. __solve (prob, alg, args... ; kwargs... )
78+ function __internal_solve_up (_prob:: $ (pType), sensealg, u0, u0_changed, p,
79+ p_changed, alg:: AbstractSimpleNonlinearSolveAlgorithm , args... ; kwargs... )
80+ prob = u0_changed || p_changed ? remake (_prob; u0, p) : _prob
81+ return SciMLBase. __solve (prob, alg, args... ; kwargs... )
82+ end
83+ end
7884end
7985
8086@setup_workload begin
0 commit comments