@@ -3,22 +3,23 @@ module SimpleNonlinearSolve
3
3
import PrecompileTools: @compile_workload , @setup_workload , @recompile_invalidations
4
4
5
5
@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
14
10
import DiffResults
11
+ import FastClosures: @closure
15
12
import ForwardDiff: Dual
16
13
import MaybeInplace: @bb , setindex_trait, CanSetindex, CannotSetindex
14
+ import NonlinearSolveBase: AbstractNonlinearTerminationMode,
15
+ AbstractSafeNonlinearTerminationMode,
16
+ AbstractSafeBestNonlinearTerminationMode,
17
+ get_termination_mode, NONLINEARSOLVE_DEFAULT_NORM
17
18
import SciMLBase: AbstractNonlinearAlgorithm, build_solution, isinplace, _unwrap_val
18
19
import StaticArraysCore: StaticArray, SVector, SMatrix, SArray, MArray, MMatrix, Size
19
20
end
20
21
21
- @reexport using ADTypes, SciMLBase
22
+ @reexport using ADTypes, SciMLBase # TODO : Reexport NonlinearSolveBase after the situation with NonlinearSolve.jl is resolved
22
23
23
24
abstract type AbstractSimpleNonlinearSolveAlgorithm <: AbstractNonlinearAlgorithm end
24
25
abstract type AbstractBracketingAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end
@@ -58,23 +59,28 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing, args...;
58
59
end
59
60
60
61
# 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
73
77
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
78
84
end
79
85
80
86
@setup_workload begin
0 commit comments