Skip to content

Commit

Permalink
🤖 Format .jl files
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira committed Jun 11, 2021
1 parent 0bb71a4 commit bfa274a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 43 deletions.
36 changes: 14 additions & 22 deletions src/feasibility-form-nls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,30 @@ optimization problem with constraints `F(x) = r` and objective `¹/₂‖r‖²`
function FeasibilityFormNLS(
nls::AbstractNLSModel{T, S};
name = "$(nls.meta.name)-ffnls",
) where {T,S}
) where {T, S}
nequ = nls.nls_meta.nequ
meta = nls.meta
nvar = meta.nvar + nequ
ncon = meta.ncon + nequ
nnzh = nls.nls_meta.nnzh + nequ + (meta.ncon == 0 ? 0 : meta.nnzh) # Some indexes can be repeated
x0 = similar(meta.x0, nvar)
x0[1 : meta.nvar] .= meta.x0
x0[meta.nvar + 1 : end] .= zero(T)
x0[1:(meta.nvar)] .= meta.x0
x0[(meta.nvar + 1):end] .= zero(T)
lvar = similar(meta.x0, nvar)
lvar[1 : meta.nvar] .= meta.lvar
lvar[meta.nvar + 1 : end] .= T(-Inf)
lvar[1:(meta.nvar)] .= meta.lvar
lvar[(meta.nvar + 1):end] .= T(-Inf)
uvar = similar(meta.x0, nvar)
uvar[1 : meta.nvar] .= meta.uvar
uvar[meta.nvar + 1 : end] .= T(Inf)
uvar[1:(meta.nvar)] .= meta.uvar
uvar[(meta.nvar + 1):end] .= T(Inf)
lcon = similar(meta.y0, ncon)
lcon[1 : nequ] .= zero(T)
lcon[nequ + 1 : end] .= meta.lcon
lcon[1:nequ] .= zero(T)
lcon[(nequ + 1):end] .= meta.lcon
ucon = similar(meta.y0, ncon)
ucon[1 : nequ] .= zero(T)
ucon[nequ + 1 : end] .= meta.ucon
ucon[1:nequ] .= zero(T)
ucon[(nequ + 1):end] .= meta.ucon
y0 = similar(meta.y0, ncon)
y0[1 : nequ] .= zero(T)
y0[nequ + 1 : end] .= meta.y0
y0[1:nequ] .= zero(T)
y0[(nequ + 1):end] .= meta.y0
meta = NLPModelMeta{T, S}(
nvar,
x0 = x0,
Expand All @@ -81,15 +81,7 @@ function FeasibilityFormNLS(
nnzh = nnzh,
name = name,
)
nls_meta = NLSMeta{T, S}(
nequ,
nvar,
x0 = x0,
nnzj = nequ,
nnzh = 0,
lin = 1:nequ,
nln = Int[],
)
nls_meta = NLSMeta{T, S}(nequ, nvar, x0 = x0, nnzj = nequ, nnzh = 0, lin = 1:nequ, nln = Int[])

nlp = FeasibilityFormNLS{T, S, typeof(nls)}(meta, nls_meta, nls, NLSCounters())
finalizer(nlp -> finalize(nlp.internal), nlp)
Expand Down
12 changes: 6 additions & 6 deletions src/model-interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ function FeasibilityFormNLS(
nnzj = meta.nnzj + nequ
nnzh = meta.nnzh + nequ
x0 = similar(meta.x0, nvar)
x0[1 : meta.nvar] .= meta.x0
x0[meta.nvar : end] .= zero(T)
x0[1:(meta.nvar)] .= meta.x0
x0[(meta.nvar):end] .= zero(T)
lvar = similar(meta.x0, nvar)
lvar[1 : meta.nvar] .= meta.lvar
lvar[meta.nvar + 1 : end] .= T(-Inf)
lvar[1:(meta.nvar)] .= meta.lvar
lvar[(meta.nvar + 1):end] .= T(-Inf)
uvar = similar(meta.x0, nvar)
uvar[1 : meta.nvar] .= meta.uvar
uvar[meta.nvar + 1 : end] .= T(Inf)
uvar[1:(meta.nvar)] .= meta.uvar
uvar[(meta.nvar + 1):end] .= T(Inf)
meta = NLPModelMeta{T, S}(
nvar,
x0 = x0,
Expand Down
12 changes: 6 additions & 6 deletions src/slack-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ function slack_meta(meta::NLPModelMeta{T, S}; name = meta.name * "-slack") where
lvar = [meta.lvar; meta.lcon[[jlow; jupp; jrng]]] # l ≤ x and cₗ ≤ s
uvar = [meta.uvar; meta.ucon[[jlow; jupp; jrng]]] # x ≤ u and s ≤ cᵤ
lcon = similar(meta.x0, meta.ncon)
lcon[setdiff(1:meta.ncon, meta.jfix)] .= zero(T)
lcon[setdiff(1:(meta.ncon), meta.jfix)] .= zero(T)
lcon[meta.jfix] = meta.lcon[meta.jfix]
ucon = similar(meta.x0, meta.ncon)
ucon[setdiff(1:meta.ncon, meta.jfix)] .= zero(T)
ucon[setdiff(1:(meta.ncon), meta.jfix)] .= zero(T)
ucon[meta.jfix] = meta.ucon[meta.jfix]

x0 = similar(meta.x0, meta.nvar + ns)
x0[1 : meta.nvar] .= meta.x0
x0[meta.nvar : end] .= zero(T)
x0[1:(meta.nvar)] .= meta.x0
x0[(meta.nvar):end] .= zero(T)
return NLPModelMeta(
meta.nvar + ns,
x0 = x0,
Expand Down Expand Up @@ -132,8 +132,8 @@ function SlackNLSModel(

meta = slack_meta(model.meta, name = name)
x0 = similar(model.meta.x0, model.meta.nvar + ns)
x0[model.meta.nvar : end] .= zero(T)
x0[1 : model.meta.nvar] .= model.meta.x0
x0[(model.meta.nvar):end] .= zero(T)
x0[1:(model.meta.nvar)] .= model.meta.x0
nls_meta = NLSMeta{T, S}(
model.nls_meta.nequ,
model.meta.nvar + ns,
Expand Down
5 changes: 3 additions & 2 deletions test/nlp/quasi-newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
c(x) = [x[1] - 2x[2] + 1; -x[1]^2 / 4 - x[2]^2 + 1]
J(x) = [1.0 -2.0; -0.5x[1] -2.0x[2]]

for (QNM, QNO) in [(LSR1Model, LSR1Operator), (LBFGSModel, LBFGSOperator)],
T in [Float64, Float32]
for (QNM, QNO) in [(LSR1Model, LSR1Operator), (LBFGSModel, LBFGSOperator)],
T in [Float64, Float32]

nlp = QNM(SimpleNLPModel(T))
n = nlp.meta.nvar
m = nlp.meta.ncon
Expand Down
1 change: 0 additions & 1 deletion test/nlp/slack-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
J(x) = [1.0 -2.0 0; -0.5x[1] -2.0x[2] -1]
H(x, y) = H(x) + y[2] * [-0.5 0 0; 0 -2.0 0; 0 0 0]


nlp = SlackModel(SimpleNLPModel(T))
n = nlp.meta.nvar
m = nlp.meta.ncon
Expand Down
4 changes: 1 addition & 3 deletions test/nls/feasibility-form-nls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
JF(x) = Float64[0 0 1 0; 0 0 0 1]
HF(x, w) = zeros(4, 4)


nls = FeasibilityFormNLS(SimpleNLSModel(T))
n = nls.meta.nvar
m = nls.meta.ncon
Expand All @@ -23,7 +22,7 @@
@test jprod_residual(nls, x, v) JF(x) * v
@test jtprod_residual(nls, x, w) JF(x)' * w
@test jprod_residual!(nls, jac_structure_residual(nls)..., jac_coord_residual(nls, x), v, Jv)
JF(x) * v
JF(x) * v
@test jtprod_residual!(
nls,
jac_structure_residual(nls)...,
Expand Down Expand Up @@ -76,7 +75,6 @@
J(x) = [-1 0 -1 0; -20x[1] 10 0 -1; 1 2x[2] 0 0; 2x[1] 1 0 0; 2x[1] 2x[2] 0 0]
H(x, y) = H(x) + diagm(0 => [-20y[2] + 2y[4] + 2y[5]; 2y[3] + 2y[5]; 0; 0])


nls = FeasibilityFormNLS(SimpleNLSModel(T))
n = nls.meta.nvar
m = nls.meta.ncon
Expand Down
2 changes: 0 additions & 2 deletions test/nls/feasibility-residual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
JF(x) = [1.0 -2.0 0; -0.5x[1] -2.0x[2] -1]
HF(x, w) = w[2] * diagm(0 => [-0.5; -2.0; 0.0])


nls = FeasibilityResidual(SimpleNLPModel(T))
n = nls.meta.nvar
ne = nls_meta(nls).nequ
Expand Down Expand Up @@ -69,7 +68,6 @@
∇f(x) = JF(x)' * F(x)
H(x) = JF(x)' * JF(x) + HF(x, F(x))


nls = FeasibilityResidual(SimpleNLPModel(T))
n = nls.meta.nvar

Expand Down
1 change: 0 additions & 1 deletion test/nls/slack-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
JF(x) = [-1.0 0 0 0; -20*x[1] 10 0 0]
HF(x, w) = w[2] * diagm(0 => [-20.0; zeros(3)])


nls = SlackNLSModel(SimpleNLSModel(T))
n = nls.meta.nvar
m = nls.meta.ncon
Expand Down

2 comments on commit bfa274a

@abelsiqueira
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/38667

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" bfa274ad13ebbc9c3d8ef603f2ce9ec3dafa6eea
git push origin v0.2.0

Please sign in to comment.