Skip to content

Fix objcons! for SimpleNLSModel #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 4, 2025
20 changes: 20 additions & 0 deletions src/nls/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,26 @@ function obj(nls::AbstractNLSModel{T, S}, x::AbstractVector) where {T, S}
return obj(nls, x, Fx)
end

"""
f, c = objcons!(nls, x, c)
f, c = objcons!(nls, x, c, Fx; recompute::Bool=true)

In-place evaluation of constraints and objective for AbstractNLSModel.
`Fx` is overwritten with the value of the residual `F(x)`.
If `recompute` is `true`, then `Fx` is updated with the residual at `x`.
"""
function objcons!(nls::AbstractNLSModel{T, S}, x::AbstractVector, c::AbstractVector) where {T, S}
@lencheck nls.meta.nvar x
@lencheck nls.meta.ncon c
Fx = S(undef, nls.nls_meta.nequ)
return objcons!(nls, x, c, Fx)
end

function objcons!(nls::AbstractNLSModel, x::AbstractVector, c::AbstractVector, Fx::AbstractVector; recompute::Bool=true)
cons_nln!(nls, x, c)
return obj(nls, x, Fx; recompute = recompute), c
end

"""
g = grad!(nls, x, g)
g = grad!(nls, x, g, Fx; recompute::Bool=true)
Expand Down
Loading