11mutable struct SimpleModel{T, S} <: AbstractNLPModel{T, S}
2- meta :: NLPModelMeta{T, S}
3- counters :: Counters
2+ meta:: NLPModelMeta{T, S}
3+ counters:: Counters
44end
55
6- SimpleModel (n :: Int ) = SimpleModel (NLPModelMeta (n, x0= ones (n)), Counters ())
6+ SimpleModel (n:: Int ) = SimpleModel (NLPModelMeta (n, x0 = ones (n)), Counters ())
77
88function NLPModels. obj (nlp:: SimpleModel , x:: AbstractVector )
99 increment! (nlp, :neval_obj )
10- sum (xi ^ 4 for xi in x) / 12
10+ sum (xi^ 4 for xi in x) / 12
1111end
1212
1313function NLPModels. grad! (nlp:: SimpleModel , x:: AbstractVector , g:: AbstractVector )
1414 increment! (nlp, :neval_grad )
15- @. g = x ^ 3 / 3
15+ @. g = x^ 3 / 3
1616 g
1717end
1818
1919function NLPModels. objgrad! (nlp:: SimpleModel , x:: AbstractVector , g:: AbstractVector )
2020 increment! (nlp, :neval_obj )
2121 increment! (nlp, :neval_grad )
22- @. g = x ^ 3 / 3
23- return sum (xi ^ 4 for xi in x) / 12 , g
22+ @. g = x^ 3 / 3
23+ return sum (xi^ 4 for xi in x) / 12 , g
2424end
2525
26- function NLPModels. hprod! (nlp:: SimpleModel , x:: AbstractVector{T} , v:: AbstractVector , Hv:: AbstractVector ; obj_weight:: T = one (T)) where T
26+ function NLPModels. hprod! (
27+ nlp:: SimpleModel ,
28+ x:: AbstractVector{T} ,
29+ v:: AbstractVector ,
30+ Hv:: AbstractVector ;
31+ obj_weight:: T = one (T),
32+ ) where {T}
2733 increment! (nlp, :neval_hprod )
28- @. Hv = obj_weight * x ^ 2 * v
34+ @. Hv = obj_weight * x^ 2 * v
2935 Hv
3036end
3137
32- function NLPModels. hess (nlp:: SimpleModel , x:: AbstractVector{T} ; obj_weight:: T = one (T)) where T
38+ function NLPModels. hess (nlp:: SimpleModel , x:: AbstractVector{T} ; obj_weight:: T = one (T)) where {T}
3339 increment! (nlp, :neval_hprod )
3440 return obj_weight .* diagm (0 => x .^ 2 )
35- end
41+ end
0 commit comments