Skip to content

Commit

Permalink
Add counters field in default counters macro (#470)
Browse files Browse the repository at this point in the history
* add counter field to default counters macro
  • Loading branch information
MaxenceGollier authored Jul 25, 2024
1 parent b8454fb commit 508033b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/nlp/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,7 @@ macro default_counters(Model, inner)
end))
push!(ex.args, :(NLPModels.increment!(nlp::$(esc(Model)), s::Symbol) = increment!(nlp.$inner, s)))
push!(ex.args, :(NLPModels.decrement!(nlp::$(esc(Model)), s::Symbol) = decrement!(nlp.$inner, s)))

push!(ex.args, :(Base.getproperty(nlp::$(esc(Model)), s::Symbol) = ( s == :counters ? nlp.$inner.counters : getfield(nlp ,s))))
ex
end
1 change: 1 addition & 0 deletions test/nlp/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ end
nlp = SuperNLPModel{Float64, Vector{Float64}}(SimpleNLPModel())
increment!(nlp, :neval_obj)
@test neval_obj(nlp.model) == 1
@test nlp.counters == nlp.model.counters
end

0 comments on commit 508033b

Please sign in to comment.