Skip to content

Commit 80bf4aa

Browse files
arnavk23tmigot
andauthored
Fix objcons! for SimpleNLSModel (#507)
* Fix objcons! for SimpleNLSModel to match test expectations: constraints in output, objective from residual * Add dual objcons! signatures for SimpleNLSModel to support new AbstractNLSModel API * objcons * Update src/nls/api.jl Co-authored-by: Tangi Migot <tangi.migot@gmail.com> * Update src/nls/api.jl Co-authored-by: Tangi Migot <tangi.migot@gmail.com> * Update simple-model.jl * changes to the NLS API and a simple model test * Update src/nls/api.jl Co-authored-by: Tangi Migot <tangi.migot@gmail.com> * Update src/nls/api.jl Co-authored-by: Tangi Migot <tangi.migot@gmail.com> * Update test/nls/simple-model.jl Co-authored-by: Tangi Migot <tangi.migot@gmail.com> --------- Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
1 parent 228c04e commit 80bf4aa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/nls/api.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,26 @@ function obj(nls::AbstractNLSModel{T, S}, x::AbstractVector) where {T, S}
451451
return obj(nls, x, Fx)
452452
end
453453

454+
"""
455+
f, c = objcons!(nls, x, c)
456+
f, c = objcons!(nls, x, c, Fx; recompute::Bool=true)
457+
458+
In-place evaluation of constraints and objective for AbstractNLSModel.
459+
`Fx` is overwritten with the value of the residual `F(x)`.
460+
If `recompute` is `true`, then `Fx` is updated with the residual at `x`.
461+
"""
462+
function objcons!(nls::AbstractNLSModel{T, S}, x::AbstractVector, c::AbstractVector) where {T, S}
463+
@lencheck nls.meta.nvar x
464+
@lencheck nls.meta.ncon c
465+
Fx = S(undef, nls.nls_meta.nequ)
466+
return objcons!(nls, x, c, Fx)
467+
end
468+
469+
function objcons!(nls::AbstractNLSModel, x::AbstractVector, c::AbstractVector, Fx::AbstractVector; recompute::Bool=true)
470+
cons_nln!(nls, x, c)
471+
return obj(nls, x, Fx; recompute = recompute), c
472+
end
473+
454474
"""
455475
g = grad!(nls, x, g)
456476
g = grad!(nls, x, g, Fx; recompute::Bool=true)

0 commit comments

Comments
 (0)