Skip to content

Commit

Permalink
remove macro @.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot committed Sep 8, 2022
1 parent a100a8f commit ffeb897
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/model-Fletcherpenaltynlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ mutable struct FletcherPenaltyNLP{
cx::T
gx::T
Aop::LinearOperators.LinearOperator{S}
JtJ::LinearOperators.LinearOperator{S} # = nlp.Aop * nlp.Aop' / not used
ys::T
gs::T
xk::T # last iterate
Expand Down Expand Up @@ -148,6 +149,8 @@ function FletcherPenaltyNLP(
nln_nnzj = nln_nnzj,
)

Aop = LinearOperator{S}(npen, nlp.meta.nvar, false, false, v -> v, v -> v, v -> v)
JtJ = Aop * Aop'
return FletcherPenaltyNLP(
meta,
Counters(),
Expand All @@ -156,7 +159,8 @@ function FletcherPenaltyNLP(
S(NaN),
Vector{S}(undef, npen),
Vector{S}(undef, nlp.meta.nvar),
LinearOperator{S}(npen, nlp.meta.nvar, false, false, v -> v, v -> v, v -> v),
Aop,
JtJ,
Vector{S}(undef, npen),
Vector{S}(undef, nlp.meta.nvar),
Vector{S}(undef, nlp.meta.nvar),
Expand Down Expand Up @@ -227,6 +231,8 @@ function FletcherPenaltyNLP(
nln_nnzj = nln_nnzj,
)
counters = Counters()
Aop = LinearOperator{S}(npen, nlp.meta.nvar, false, false, v -> v, v -> v, v -> v)
JtJ = Aop * Aop'
return FletcherPenaltyNLP(
meta,
counters,
Expand All @@ -235,7 +241,8 @@ function FletcherPenaltyNLP(
S(NaN),
Vector{S}(undef, npen),
Vector{S}(undef, nlp.meta.nvar),
LinearOperator{S}(npen, nlp.meta.nvar, false, false, v -> v, v -> v, v -> v),
Aop,
JtJ,
Vector{S}(undef, npen),
Vector{S}(undef, nlp.meta.nvar),
Vector{S}(undef, nlp.meta.nvar),
Expand Down Expand Up @@ -613,18 +620,18 @@ function hprod!(
g = nlp.gx
c = nlp.cx

@. nlp.Jv = -ys
nlp.Jv .= .-ys
hprod_nln!(nlp, x, nlp.Jv, v, nlp.Hsv, obj_weight = one(T))
#Hsv = hprod(nlp.nlp, x, -ys+ρ*c, v, obj_weight = 1.0)

(p1, _, p2, _) = solve_two_least_squares(nlp, x, v, nlp.Hsv)
@. nlp.Hsv = v - p1 # Ptv = v - p1
nlp.Hsv .= v .- p1 # Ptv = v - p1
hprod_nln!(nlp, x, nlp.Jv, nlp.Hsv, nlp.v, obj_weight = one(T)) # HsPtv = hprod(nlp.nlp, x, -ys, Ptv, obj_weight = one(T))

# PtHsv = nlp.Hsv - pt_sol2[1:nvar]
# Hv .= nlp.Hsv - PtHsv - nlp.v + 2 * T(σ) * Ptv
# Hv .= pt_sol2[1:nvar] - nlp.v + 2 * T(σ) * Ptv
@. Hv = p2 - nlp.v + 2 * T(σ) * nlp.Hsv
Hv .= p2 .- nlp.v .+ 2 .* T(σ) .* nlp.Hsv

if ρ > 0.0
if nlp.explicit_linear_constraints
Expand All @@ -636,10 +643,10 @@ function hprod!(
end
hprod_nln!(nlp, x, c, v, nlp.v, obj_weight = zero(T)) # Hcv = hprod(nlp.nlp, x, c, v, obj_weight = zero(T))

@. Hv += nlp.v + T(ρ) * nlp.Jcρ
Hv .+= nlp.v .+ T(ρ) .* nlp.Jcρ
end
if nlp.η > 0.0
@. Hv += T(nlp.η) * v
Hv .+= T(nlp.η) .* v
end

Hv .*= obj_weight
Expand Down Expand Up @@ -667,10 +674,10 @@ function hprod!(
hprod_nln!(nlp, x, -ys, v, nlp.Hsv, obj_weight = one(T))

(p1, _, p2, _) = solve_two_least_squares(nlp, x, v, nlp.Hsv)
@. nlp.Hsv = v - p1 # Ptv = v - p1
nlp.Hsv .= v .- p1 # Ptv = v - p1
# PtHsv = nlp.Hsv - p2

@. nlp.Jv = -ys
nlp.Jv .= .-ys
# HsPtv = nlp.Jcρ
hprod_nln!(nlp, x, nlp.Jv, nlp.Hsv, nlp.Jcρ, obj_weight = one(T))

Expand All @@ -686,9 +693,9 @@ function hprod!(
# @. Hv = nlp.Hsv - PtHsv - HsPtv + 2 * T(σ) * Ptv - nlp.v - SsinvJtJJv
# @. Hv = p2 - HsPtv + 2 * T(σ) * nlp.Hsv - nlp.v - SsinvJtJJv
# @. Hv = p2 - nlp.Jcρ + 2 * T(σ) * nlp.Hsv - nlp.v - SsinvJtJJv
@. Hv = p2 - nlp.Jcρ + 2 * T(σ) * nlp.Hsv - nlp.v
Hv .= p2 .- nlp.Jcρ .+ 2 .* T(σ) .* nlp.Hsv .- nlp.v
hprod_nln!(nlp, x, invJtJJv, gs, nlp.Jcρ, obj_weight = zero(T)) # SsinvJtJJv
@. Hv -= nlp.Jcρ
Hv .-= nlp.Jcρ

if ρ > 0.0
if nlp.explicit_linear_constraints
Expand All @@ -700,10 +707,10 @@ function hprod!(
end
hprod_nln!(nlp, x, c, v, nlp.v, obj_weight = zero(T)) # Hcv = hprod(nlp.nlp, x, c, v, obj_weight = zero(T))

@. Hv += T(ρ) * (nlp.v + nlp.Jcρ)
Hv .+= T(ρ) .* (nlp.v .+ nlp.Jcρ)
end
if nlp.η > 0.0
@. Hv += T(nlp.η) * v
Hv .+= T(nlp.η) .* v
end

Hv .*= obj_weight
Expand Down

0 comments on commit ffeb897

Please sign in to comment.