Skip to content

Commit

Permalink
Add function without increment! (#103)
Browse files Browse the repository at this point in the history
* Add `jprod!`

Skip the increment! that allocate occasionally

* Add `cons!` without increment!

* add increment!
  • Loading branch information
tmigot authored Jul 7, 2023
1 parent e289ac3 commit 98704d1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/slack-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ function NLPModels.objgrad!(nlp::SlackModels, x::AbstractVector, g::AbstractVect
return f, g
end

function NLPModels.cons!(nlp::SlackModels, x::AbstractVector, cx::AbstractVector)
@lencheck nlp.meta.nvar x
@lencheck nlp.meta.ncon cx
increment!(nlp.model, :neval_cons)
nlp.meta.nlin > 0 && cons_lin!(nlp, x, view(cx, nlp.meta.lin))
nlp.meta.nnln > 0 && cons_nln!(nlp, x, view(cx, nlp.meta.nln))
return cx
end

function NLPModels.cons_lin!(nlp::SlackModels, x::AbstractVector, c::AbstractVector)
@lencheck nlp.meta.nvar x
@lencheck nlp.meta.nlin c
Expand Down Expand Up @@ -382,6 +391,20 @@ function NLPModels.jac_nln_coord!(nlp::SlackModels, x::AbstractVector, vals::Abs
return vals
end

function NLPModels.jprod!(
nlp::SlackModels,
x::AbstractVector,
v::AbstractVector,
Jv::AbstractVector,
)
@lencheck nlp.meta.nvar x v
@lencheck nlp.meta.ncon Jv
increment!(nlp.model, :neval_jprod)
nlp.meta.nlin > 0 && jprod_lin!(nlp, x, v, view(Jv, nlp.meta.lin))
nlp.meta.nnln > 0 && jprod_nln!(nlp, x, v, view(Jv, nlp.meta.nln))
return Jv
end

function NLPModels.jprod_lin!(
nlp::SlackModels,
x::AbstractVector,
Expand Down

0 comments on commit 98704d1

Please sign in to comment.