Skip to content
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

fill-in! with the same jacobian matrix #103

Merged
merged 4 commits into from
Aug 18, 2022
Merged
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
27 changes: 20 additions & 7 deletions src/Stopping/NLPStoppingmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function fill_in!(
lambda::Union{T, Nothing} = nothing,
mu::Union{T, Nothing} = nothing,
matrix_info::Bool = true,
convert::Bool = true,
kwargs...,
) where {Pb, M, SRC, MStp, LoS, S, T}
gfx = isnothing(fx) ? obj(stp.pb, x) : fx
Expand All @@ -225,11 +226,17 @@ function fill_in!(
if isnothing(Hx) && matrix_info
gHx = hess(stp.pb, x).data
else
gHx = Hx
gHx = isnothing(Hx) ? zeros(eltype(T), 0, 0) : Hx
end

if stp.pb.meta.ncon > 0
gJx = isnothing(Jx) ? jac(stp.pb, x) : Jx
gJx = if !isnothing(Jx)
Jx
elseif typeof(stp.current_state.Jx) <: LinearOperator
jac_op(stp.pb, x)
else # typeof(stp.current_state.Jx) <: SparseArrays.SparseMatrixCSC
jac(stp.pb, x)
end
gcx = isnothing(cx) ? cons(stp.pb, x) : cx
else
gJx = stp.current_state.Jx
Expand All @@ -239,13 +246,18 @@ function fill_in!(
#update the Lagrange multiplier if one of the 2 is asked
if (stp.pb.meta.ncon > 0 || has_bounds(stp.pb)) && (isnothing(lambda) || isnothing(mu))
lb, lc = _compute_mutliplier(stp.pb, x, ggx, gcx, gJx; kwargs...)
elseif stp.pb.meta.ncon == 0 && !has_bounds(stp.pb) && isnothing(lambda)
lb, lc = mu, stp.current_state.lambda
else
lb, lc = mu, lambda
lb = if isnothing(mu) & has_bounds(stp.pb)
zeros(eltype(T), get_nvar(stp.pb))
elseif isnothing(mu) & !has_bounds(stp.pb)
zeros(eltype(T), 0)
else
mu
end
lc = isnothing(lambda) ? zeros(eltype(T), get_ncon(stp.pb)) : lambda
end

return update!(stp, x = x, fx = gfx, gx = ggx, Hx = gHx, cx = gcx, Jx = gJx, mu = lb, lambda = lc)
return update!(stp, x = x, fx = gfx, gx = ggx, Hx = gHx, cx = gcx, Jx = gJx, mu = lb, lambda = lc, convert = convert)
end

function fill_in!(
Expand All @@ -255,14 +267,15 @@ function fill_in!(
gx::Union{T, Nothing} = nothing,
f₀::Union{T, Nothing} = nothing,
g₀::Union{T, Nothing} = nothing,
convert::Bool = true,
kwargs...,
) where {Pb, M, SRC, S, T, MStp, LoS}
gfx = isnothing(fx) ? obj(stp.pb, x) : fx
ggx = isnothing(gx) ? grad(stp.pb, x) : gx
gf₀ = isnothing(f₀) ? obj(stp.pb, 0.0) : f₀
gg₀ = isnothing(g₀) ? grad(stp.pb, 0.0) : g₀

return update!(stp.current_state, x = x, fx = gfx, gx = ggx, f₀ = gf₀, g₀ = gg₀)
return update!(stp.current_state, x = x, fx = gfx, gx = ggx, f₀ = gf₀, g₀ = gg₀, convert = convert)
end

"""
Expand Down