@@ -53,91 +53,95 @@ promote_objtype(method::ZerothOrderOptimizer, x, autodiff::Symbol, inplace::Bool
5353promote_objtype (method:: FirstOrderOptimizer , x, autodiff:: Symbol , inplace:: Bool , td:: TwiceDifferentiable ) = td
5454promote_objtype (method:: SecondOrderOptimizer , x, autodiff:: Symbol , inplace:: Bool , td:: TwiceDifferentiable ) = td
5555
56- for optimize in [:optimize , :optimizing ]
57- @eval begin
58-
5956# if no method or options are present
60- function $optimize (f, initial_x:: AbstractArray ; inplace = true , autodiff = :finite , kwargs... )
57+ function optimizing (f, initial_x:: AbstractArray ; inplace = true , autodiff = :finite , kwargs... )
6158 method = fallback_method (f)
6259 checked_kwargs, method = check_kwargs (kwargs, method)
6360 d = promote_objtype (method, initial_x, autodiff, inplace, f)
6461 add_default_opts! (checked_kwargs, method)
6562
6663 options = Options (; checked_kwargs... )
67- $ optimize (d, initial_x, method, options)
64+ optimizing (d, initial_x, method, options)
6865end
69- function $optimize (f, g, initial_x:: AbstractArray ; inplace = true , autodiff = :finite , kwargs... )
66+ function optimizing (f, g, initial_x:: AbstractArray ; inplace = true , autodiff = :finite , kwargs... )
7067
7168 method = fallback_method (f, g)
7269 checked_kwargs, method = check_kwargs (kwargs, method)
7370 d = promote_objtype (method, initial_x, autodiff, inplace, f, g)
7471 add_default_opts! (checked_kwargs, method)
7572
7673 options = Options (; checked_kwargs... )
77- $ optimize (d, initial_x, method, options)
74+ optimizing (d, initial_x, method, options)
7875end
79- function $optimize (f, g, h, initial_x:: AbstractArray ; inplace = true , autodiff = :finite , kwargs... )
76+ function optimizing (f, g, h, initial_x:: AbstractArray ; inplace = true , autodiff = :finite , kwargs... )
8077
8178 method = fallback_method (f, g, h)
8279 checked_kwargs, method = check_kwargs (kwargs, method)
8380 d = promote_objtype (method, initial_x, autodiff, inplace, f, g, h)
8481 add_default_opts! (checked_kwargs, method)
8582
8683 options = Options (; checked_kwargs... )
87- $ optimize (d, initial_x, method, options)
84+ optimizing (d, initial_x, method, options)
8885end
8986
9087# no method supplied with objective
91- function $optimize (d:: T , initial_x:: AbstractArray , options:: Options ) where T<: AbstractObjective
92- $ optimize (d, initial_x, fallback_method (d), options)
88+ function optimizing (d:: T , initial_x:: AbstractArray , options:: Options ) where T<: AbstractObjective
89+ optimizing (d, initial_x, fallback_method (d), options)
9390end
9491# no method supplied with inplace and autodiff keywords becauase objective is not supplied
95- function $optimize (f, initial_x:: AbstractArray , options:: Options ; inplace = true , autodiff = :finite )
92+ function optimizing (f, initial_x:: AbstractArray , options:: Options ; inplace = true , autodiff = :finite )
9693 method = fallback_method (f)
9794 d = promote_objtype (method, initial_x, autodiff, inplace, f)
98- $ optimize (d, initial_x, method, options)
95+ optimizing (d, initial_x, method, options)
9996end
100- function $optimize (f, g, initial_x:: AbstractArray , options:: Options ; inplace = true , autodiff = :finite )
97+ function optimizing (f, g, initial_x:: AbstractArray , options:: Options ; inplace = true , autodiff = :finite )
10198
10299 method = fallback_method (f, g)
103100 d = promote_objtype (method, initial_x, autodiff, inplace, f, g)
104- $ optimize (d, initial_x, method, options)
101+ optimizing (d, initial_x, method, options)
105102end
106- function $optimize (f, g, h, initial_x:: AbstractArray{T} , options:: Options ; inplace = true , autodiff = :finite ) where {T}
103+ function optimizing (f, g, h, initial_x:: AbstractArray{T} , options:: Options ; inplace = true , autodiff = :finite ) where {T}
107104
108105 method = fallback_method (f, g, h)
109106 d = promote_objtype (method, initial_x, autodiff, inplace, f, g, h)
110107
111- $ optimize (d, initial_x, method, options)
108+ optimizing (d, initial_x, method, options)
112109end
113110
114111# potentially everything is supplied (besides caches)
115- function $optimize (f, initial_x:: AbstractArray , method:: AbstractOptimizer ,
112+ function optimizing (f, initial_x:: AbstractArray , method:: AbstractOptimizer ,
116113 options:: Options = Options (;default_options (method)... ); inplace = true , autodiff = :finite )
117114
118115 d = promote_objtype (method, initial_x, autodiff, inplace, f)
119- $ optimize (d, initial_x, method, options)
116+ optimizing (d, initial_x, method, options)
120117end
121- function $optimize (f, g, initial_x:: AbstractArray , method:: AbstractOptimizer ,
118+ function optimizing (f, g, initial_x:: AbstractArray , method:: AbstractOptimizer ,
122119 options:: Options = Options (;default_options (method)... ); inplace = true , autodiff = :finite )
123120
124121 d = promote_objtype (method, initial_x, autodiff, inplace, f, g)
125122
126- $ optimize (d, initial_x, method, options)
123+ optimizing (d, initial_x, method, options)
127124end
128- function $optimize (f, g, h, initial_x:: AbstractArray{T} , method:: AbstractOptimizer ,
125+ function optimizing (f, g, h, initial_x:: AbstractArray{T} , method:: AbstractOptimizer ,
129126 options:: Options = Options (;default_options (method)... ); inplace = true , autodiff = :finite ) where T
130127
131128 d = promote_objtype (method, initial_x, autodiff, inplace, f, g, h)
132129
133- $ optimize (d, initial_x, method, options)
130+ optimizing (d, initial_x, method, options)
134131end
135132
136- function $optimize (d:: D , initial_x:: AbstractArray , method:: SecondOrderOptimizer ,
133+ function optimizing (d:: D , initial_x:: AbstractArray , method:: SecondOrderOptimizer ,
137134 options:: Options = Options (;default_options (method)... ); autodiff = :finite , inplace = true ) where {D <: Union{NonDifferentiable, OnceDifferentiable} }
138135 d = promote_objtype (method, initial_x, autodiff, inplace, d)
139- $ optimize (d, initial_x, method, options)
136+ optimizing (d, initial_x, method, options)
140137end
141138
142- end # eval
143- end # for
139+ function optimize (args... ; kwargs... )
140+ local istate
141+ for istate′ in optimizing (args... ; kwargs... )
142+ istate = istate′
143+ end
144+ # We can safely assume that `istate` is defined at this point. That is to say,
145+ # `OptimIterator` guarantees that `iterate(::OptimIterator) !== nothing`.
146+ return OptimizationResults (istate)
147+ end
0 commit comments