Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/quasi-newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ NLPModels.jac_nln_structure!(
# the following methods are affected by the Hessian approximation
NLPModels.hess_op(nlp::QuasiNewtonModel, x::AbstractVector; kwargs...) = nlp.op
NLPModels.hprod(nlp::QuasiNewtonModel, x::AbstractVector, v::AbstractVector; kwargs...) = nlp.op * v

function NLPModels.hprod!(
nlp::QuasiNewtonModel,
x::AbstractVector,
Expand All @@ -129,6 +130,9 @@ function NLPModels.hprod!(
return Hv
end

NLPModels.neval_hprod(nlp::LBFGSModel) = nlp.op.nprod
NLPModels.neval_hprod(nlp::LSR1Model) = nlp.op.nprod

function Base.push!(nlp::QuasiNewtonModel, args...)
push!(nlp.op, args...)
return nlp
Expand Down
3 changes: 3 additions & 0 deletions test/nlp/quasi-newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
@test obj(nlp, x) ≈ f(x)
@test grad(nlp, x) ≈ ∇f(x)
@test hprod(nlp, x, v) ≈ H(x) * v
@test neval_hprod(nlp.model) == 0
(QNM == LSR1Model) && (@test neval_hprod(nlp) == 2)
(QNM == LBFGSModel) && (@test neval_hprod(nlp) == 1)
@test cons(nlp, x) ≈ c(x)
@test jac(nlp, x) ≈ J(x)
@test jprod(nlp, x, v) ≈ J(x) * v
Expand Down