From bfa274ad13ebbc9c3d8ef603f2ce9ec3dafa6eea Mon Sep 17 00:00:00 2001 From: abelsiqueira Date: Fri, 11 Jun 2021 13:03:12 +0000 Subject: [PATCH] :robot: Format .jl files --- src/feasibility-form-nls.jl | 36 +++++++++++++------------------- src/model-interaction.jl | 12 +++++------ src/slack-model.jl | 12 +++++------ test/nlp/quasi-newton.jl | 5 +++-- test/nlp/slack-model.jl | 1 - test/nls/feasibility-form-nls.jl | 4 +--- test/nls/feasibility-residual.jl | 2 -- test/nls/slack-model.jl | 1 - 8 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/feasibility-form-nls.jl b/src/feasibility-form-nls.jl index 5438554..3a6ef43 100644 --- a/src/feasibility-form-nls.jl +++ b/src/feasibility-form-nls.jl @@ -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, @@ -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) diff --git a/src/model-interaction.jl b/src/model-interaction.jl index fa61542..cfa5bf1 100644 --- a/src/model-interaction.jl +++ b/src/model-interaction.jl @@ -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, diff --git a/src/slack-model.jl b/src/slack-model.jl index 6de717c..cd35eca 100644 --- a/src/slack-model.jl +++ b/src/slack-model.jl @@ -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, @@ -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, diff --git a/test/nlp/quasi-newton.jl b/test/nlp/quasi-newton.jl index cce2936..d33a414 100644 --- a/test/nlp/quasi-newton.jl +++ b/test/nlp/quasi-newton.jl @@ -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 diff --git a/test/nlp/slack-model.jl b/test/nlp/slack-model.jl index 57a842b..cb63aef 100644 --- a/test/nlp/slack-model.jl +++ b/test/nlp/slack-model.jl @@ -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 diff --git a/test/nls/feasibility-form-nls.jl b/test/nls/feasibility-form-nls.jl index 85860f1..51853ca 100644 --- a/test/nls/feasibility-form-nls.jl +++ b/test/nls/feasibility-form-nls.jl @@ -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 @@ -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)..., @@ -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 diff --git a/test/nls/feasibility-residual.jl b/test/nls/feasibility-residual.jl index de04bf3..cce9fc3 100644 --- a/test/nls/feasibility-residual.jl +++ b/test/nls/feasibility-residual.jl @@ -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 @@ -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 diff --git a/test/nls/slack-model.jl b/test/nls/slack-model.jl index 188d32e..0dcb052 100644 --- a/test/nls/slack-model.jl +++ b/test/nls/slack-model.jl @@ -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