Skip to content

Commit 9bc0278

Browse files
committed
🤖 Format .jl files
1 parent 91918e7 commit 9bc0278

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

test/simple_model.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
11
mutable struct SimpleModel{T, S} <: AbstractNLPModel{T, S}
2-
meta :: NLPModelMeta{T, S}
3-
counters :: Counters
2+
meta::NLPModelMeta{T, S}
3+
counters::Counters
44
end
55

6-
SimpleModel(n :: Int) = SimpleModel(NLPModelMeta(n, x0=ones(n)), Counters())
6+
SimpleModel(n::Int) = SimpleModel(NLPModelMeta(n, x0 = ones(n)), Counters())
77

88
function NLPModels.obj(nlp::SimpleModel, x::AbstractVector)
99
increment!(nlp, :neval_obj)
10-
sum(xi ^ 4 for xi in x) / 12
10+
sum(xi^4 for xi in x) / 12
1111
end
1212

1313
function NLPModels.grad!(nlp::SimpleModel, x::AbstractVector, g::AbstractVector)
1414
increment!(nlp, :neval_grad)
15-
@. g = x ^ 3 / 3
15+
@. g = x^3 / 3
1616
g
1717
end
1818

1919
function NLPModels.objgrad!(nlp::SimpleModel, x::AbstractVector, g::AbstractVector)
2020
increment!(nlp, :neval_obj)
2121
increment!(nlp, :neval_grad)
22-
@. g = x ^ 3 / 3
23-
return sum(xi ^4 for xi in x) / 12, g
22+
@. g = x^3 / 3
23+
return sum(xi^4 for xi in x) / 12, g
2424
end
2525

26-
function NLPModels.hprod!(nlp::SimpleModel, x::AbstractVector{T}, v::AbstractVector, Hv::AbstractVector; obj_weight::T = one(T)) where T
26+
function NLPModels.hprod!(
27+
nlp::SimpleModel,
28+
x::AbstractVector{T},
29+
v::AbstractVector,
30+
Hv::AbstractVector;
31+
obj_weight::T = one(T),
32+
) where {T}
2733
increment!(nlp, :neval_hprod)
28-
@. Hv = obj_weight * x ^ 2 * v
34+
@. Hv = obj_weight * x^2 * v
2935
Hv
3036
end
3137

32-
function NLPModels.hess(nlp::SimpleModel, x::AbstractVector{T}; obj_weight::T = one(T)) where T
38+
function NLPModels.hess(nlp::SimpleModel, x::AbstractVector{T}; obj_weight::T = one(T)) where {T}
3339
increment!(nlp, :neval_hprod)
3440
return obj_weight .* diagm(0 => x .^ 2)
35-
end
41+
end

test/test_linesearch.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ allocate:
2424
```
2525
"""
2626
macro wrappedallocs(expr)
27-
argnames = [gensym() for a in expr.args]
28-
quote
29-
function g($(argnames...))
30-
@allocated $(Expr(expr.head, argnames...))
31-
end
32-
$(Expr(:call, :g, [esc(a) for a in expr.args]...))
27+
argnames = [gensym() for a in expr.args]
28+
quote
29+
function g($(argnames...))
30+
@allocated $(Expr(expr.head, argnames...))
3331
end
32+
$(Expr(:call, :g, [esc(a) for a in expr.args]...))
33+
end
3434
end
3535

3636
@testset "Linesearch" begin
@@ -128,11 +128,11 @@ end
128128
@test al == 0
129129

130130
function armijo_wolfe_alloc(lm, h₀, slope, g, bk_max)
131-
@allocated armijo_wolfe(lm, h₀, slope, g, bk_max=bk_max)
131+
@allocated armijo_wolfe(lm, h₀, slope, g, bk_max = bk_max)
132132
end
133133

134134
for bk_max = 0:8
135-
(t, gg, ht, nbk, nbW) = armijo_wolfe(lm, h₀, slope, g, bk_max=bk_max)
135+
(t, gg, ht, nbk, nbW) = armijo_wolfe(lm, h₀, slope, g, bk_max = bk_max)
136136
al = armijo_wolfe_alloc(lm, h₀, slope, g, bk_max)
137137
@test al == 0
138138
end

0 commit comments

Comments
 (0)