Skip to content

Commit 8667abc

Browse files
committed
formatting
1 parent c0e347c commit 8667abc

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/NonconvexPercival.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import NonconvexCore: Workspace, reset!, optimize!
1212
struct PercivalAlg <: AbstractOptimizer end
1313
const AugLag = PercivalAlg
1414

15-
struct PercivalOptions{T <: NamedTuple}
15+
struct PercivalOptions{T<:NamedTuple}
1616
nt::T
1717
end
1818
function PercivalOptions(; first_order = true, memory = 5, kwargs...)
@@ -25,7 +25,13 @@ function PercivalOptions(; first_order = true, memory = 5, kwargs...)
2525
end
2626
const AugLagOptions = PercivalOptions
2727

28-
mutable struct PercivalWorkspace{TM <: VecModel, TP <: Percival.NLPModels.AbstractNLPModel, TX <: AbstractVector, TO <: PercivalOptions, TC <: Base.RefValue{Int}} <: Workspace
28+
mutable struct PercivalWorkspace{
29+
TM<:VecModel,
30+
TP<:Percival.NLPModels.AbstractNLPModel,
31+
TX<:AbstractVector,
32+
TO<:PercivalOptions,
33+
TC<:Base.RefValue{Int},
34+
} <: Workspace
2935
model::TM
3036
problem::TP
3137
x0::TX
@@ -41,7 +47,7 @@ function PercivalWorkspace(
4147
problem, counter = get_percival_problem(model, copy(x0))
4248
return PercivalWorkspace(model, problem, copy(x0), options, counter)
4349
end
44-
struct PercivalResult{TM1, TM2, TP, TR, TF} <: AbstractResult
50+
struct PercivalResult{TM1,TM2,TP,TR,TF} <: AbstractResult
4551
minimizer::TM1
4652
minimum::TM2
4753
problem::TP

test/runtests.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,14 @@ end
110110
component_pdf(x::Real, mu::Real, tau::Real) =
111111
tau * exp(-tau^2 * (x - mu)^2 / 2) / sqrt(2π)
112112
data = randn(StableRNG(123), 40)
113-
loss(params::AbstractVector) = -sum(log,
114-
(1 - params[1]) * component_pdf(x, 0, 1)
115-
+ params[1] * component_pdf(x, params[2], params[3])
116-
for x in data
117-
)
113+
loss(params::AbstractVector) =
114+
-sum(
115+
log,
116+
(1 - params[1]) * component_pdf(x, 0, 1) +
117+
params[1] * component_pdf(x, params[2], params[3]) for x in data
118+
)
118119
model = Model(loss)
119-
addvar!(model, [0, -Inf, 0], [1, Inf, Inf], init=[0.1, 0, 1])
120-
res = optimize(model, AugLag(), [0.1, -3, 1], options=AugLagOptions())
121-
@test res.minimizer == [
122-
0.0,
123-
-2.3140286844577305,
124-
0.06904076799516767,
125-
]
120+
addvar!(model, [0, -Inf, 0], [1, Inf, Inf], init = [0.1, 0, 1])
121+
res = optimize(model, AugLag(), [0.1, -3, 1], options = AugLagOptions())
122+
@test res.minimizer == [0.0, -2.3140286844577305, 0.06904076799516767]
126123
end

0 commit comments

Comments
 (0)