Skip to content

Commit 94d9f9f

Browse files
Format .jl files (#73)
Co-authored-by: sshin23 <sshin23@users.noreply.github.com>
1 parent 610a1af commit 94d9f9f

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

ext/ExaModelsMOI.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,14 @@ end
334334
function _exafy(e::MOI.ScalarAffineFunction{T}, p = ()) where {T}
335335
ec = if !isempty(e.terms)
336336
sum(begin
337-
c1, p = _exafy(term, p)
338-
c1
339-
end for term in e.terms) + ExaModels.ParIndexed(ExaModels.ParSource(), length(p) + 1)
337+
c1, p = _exafy(term, p)
338+
c1
339+
end for term in e.terms) +
340+
ExaModels.ParIndexed(ExaModels.ParSource(), length(p) + 1)
340341
else
341342
ExaModels.ParIndexed(ExaModels.ParSource(), length(p) + 1)
342343
end
343-
344+
344345
return ec, (p..., e.constant)
345346
end
346347

src/nlp.jl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -256,35 +256,35 @@ end
256256
Var(v.offset + idxx(is .- (_start.(v.size) .- 1), _length.(v.size)))
257257
end
258258

259-
function _bound_check(sizes, i::I) where I <: Integer
259+
function _bound_check(sizes, i::I) where {I<:Integer}
260260
__bound_check(sizes[1], i)
261261
end
262-
function _bound_check(sizes, is::NTuple{N,I}) where {I <: Integer, N}
262+
function _bound_check(sizes, is::NTuple{N,I}) where {I<:Integer,N}
263263
__bound_check(sizes[1], is[1])
264264
_bound_check(sizes[2:end], is[2:end])
265265
end
266266
_bound_check(sizes, is) = nothing
267267
_bound_check(sizes, is::Tuple{}) = nothing
268268

269-
function __bound_check(a::I,b::I) where I <: Integer
270-
@assert(1<= b <= a, "Variable index bound error")
269+
function __bound_check(a::I, b::I) where {I<:Integer}
270+
@assert(1 <= b <= a, "Variable index bound error")
271271
end
272-
function __bound_check(a::UnitRange{Int},b::I) where I <: Integer
272+
function __bound_check(a::UnitRange{Int}, b::I) where {I<:Integer}
273273
@assert(b in a, "Variable index bound error")
274274
end
275275

276276

277277
function append!(backend, a, b::Base.Generator, lb)
278278
b = _adapt_gen(b)
279-
279+
280280
la = length(a)
281281
resize!(a, la + lb)
282282
map!(b.f, view(a, (la+1):(la+lb)), convert_array(b.iter, backend))
283283
return a
284284
end
285285

286286
function append!(backend, a, b::Base.Generator{UnitRange{I}}, lb) where {I}
287-
287+
288288
la = length(a)
289289
resize!(a, la + lb)
290290
map!(b.f, view(a, (la+1):(la+lb)), b.iter)
@@ -450,8 +450,8 @@ function constraint(
450450
start = zero(T),
451451
lcon = zero(T),
452452
ucon = zero(T),
453-
) where {T,C<:ExaCore{T}}
454-
453+
) where {T,C<:ExaCore{T}}
454+
455455
gen = _adapt_gen(gen)
456456
f = SIMDFunction(gen, c.ncon, c.nnzj, c.nnzh)
457457
pars = gen.iter
@@ -512,7 +512,7 @@ function _constraint(c, f, pars, start, lcon, ucon)
512512
end
513513

514514
function constraint!(c::C, c1, gen::Base.Generator) where {C<:ExaCore}
515-
515+
516516
gen = _adapt_gen(gen)
517517
f = SIMDFunction(gen, offset0(c1, 0), c.nnzj, c.nnzh)
518518
pars = gen.iter
@@ -648,7 +648,7 @@ function hess_coord!(
648648
x::AbstractVector,
649649
y::AbstractVector,
650650
hess::AbstractVector;
651-
obj_weight = one(eltype(x)),
651+
obj_weight = one(eltype(x)),
652652
)
653653

654654
fill!(hess, zero(eltype(hess)))
@@ -707,21 +707,23 @@ end
707707
@inbounds @inline offset0(a::C, i) where {C<:ConstraintAug} = offset0(a.f, a.itr, i)
708708
@inbounds @inline offset0(f::F, itr, i) where {P<:Pair,F<:SIMDFunction{P}} =
709709
f.o0 + f.f.first(itr[i], nothing)
710-
@inbounds @inline offset0(f::F, itr, i) where {T<:Tuple,P<:Pair{T},F<:SIMDFunction{P}} = f.o0 + idxx(coord(itr, i, f.f.first), Base.size(itr))
710+
@inbounds @inline offset0(f::F, itr, i) where {T<:Tuple,P<:Pair{T},F<:SIMDFunction{P}} =
711+
f.o0 + idxx(coord(itr, i, f.f.first), Base.size(itr))
711712

712713
@inline idx(itr, I) = @inbounds itr[I]
713-
@inline idx(itr::Base.Iterators.ProductIterator{V}, I) where V = _idx(I-1, itr.iterators, Base.size(itr))
714+
@inline idx(itr::Base.Iterators.ProductIterator{V}, I) where {V} =
715+
_idx(I - 1, itr.iterators, Base.size(itr))
714716
@inline function _idx(n, (vec1, vec...), (si1, si...))
715717
d, r = divrem(n, si1)
716-
return (vec1[r + 1], _idx(d, vec, si)...)
718+
return (vec1[r+1], _idx(d, vec, si)...)
717719
end
718-
@inline _idx(n, (vec,), ::Tuple{Int}) = @inbounds vec[n + 1]
720+
@inline _idx(n, (vec,), ::Tuple{Int}) = @inbounds vec[n+1]
719721

720722
@inline idxx(coord, si) = _idxx(coord, si, 1) + 1
721-
@inline _idxx(coord, si, a) = a * (coord[1] - 1) + _idxx(coord[2:end], si[2:end], a*si[1])
723+
@inline _idxx(coord, si, a) = a * (coord[1] - 1) + _idxx(coord[2:end], si[2:end], a * si[1])
722724
@inline _idxx(::Tuple{}, ::Tuple{}, a) = 0
723725

724-
@inline coord(itr, i, (f,fs...)) = (f(idx(itr,i), nothing), coord(itr, i, fs)...)
726+
@inline coord(itr, i, (f, fs...)) = (f(idx(itr, i), nothing), coord(itr, i, fs)...)
725727
@inline coord(itr, i, ::Tuple{}) = ()
726728

727729
for (thing, val) in [(:solution, 1), (:multipliers_L, 0), (:multipliers_U, 2)]
@@ -801,4 +803,4 @@ end
801803

802804

803805
_adapt_gen(gen) = Base.Generator(gen.f, collect(gen.iter))
804-
_adapt_gen(gen::Base.Generator{P}) where P <: Union{AbstractArray,AbstractRange} = gen
806+
_adapt_gen(gen::Base.Generator{P}) where {P<:Union{AbstractArray,AbstractRange}} = gen

test/NLPTest/NLPTest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function runtests()
136136

137137
m, vars2, cons2 = jump_model(nothing, args)
138138
m2 = MathOptNLPModel(m)
139-
139+
140140
set_optimizer(m, MadNLP.Optimizer)
141141
set_optimizer_attribute(m, "print_level", MadNLP.ERROR)
142142
optimize!(m)

test/NLPTest/luksan.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function luksan_vlcek_con1(x, i, j)
77
end
88
function luksan_vlcek_con2(x, i, j)
99
return sin(x[i+1, j] - x[i+2, j])sin(x[i+1, j] + x[i+2, j]) + 4x[i+1, j] -
10-
x[i, j]exp(x[i, j] - x[i+1, j]) - 3
10+
x[i, j]exp(x[i, j] - x[i+1, j]) - 3
1111
end
1212

1313
function luksan_vlcek_x0(i)
@@ -17,30 +17,35 @@ end
1717
function _exa_luksan_vlcek_model(backend, N; M = 1)
1818

1919
c = ExaCore(backend = backend)
20-
x = variable(c, N, M; start = [luksan_vlcek_x0(i) for i = 1:N, j=1:M])
21-
s = constraint(c, luksan_vlcek_con1(x, i, j) for i = 1:N-2, j=1:M)
22-
constraint!(c, s, (i,j) => luksan_vlcek_con2(x, i, j) for i = 1:N-2, j=1:M)
23-
objective(c, luksan_vlcek_obj(x, i, j) for i = 2:N, j=1:M)
20+
x = variable(c, N, M; start = [luksan_vlcek_x0(i) for i = 1:N, j = 1:M])
21+
s = constraint(c, luksan_vlcek_con1(x, i, j) for i = 1:N-2, j = 1:M)
22+
constraint!(c, s, (i, j) => luksan_vlcek_con2(x, i, j) for i = 1:N-2, j = 1:M)
23+
objective(c, luksan_vlcek_obj(x, i, j) for i = 2:N, j = 1:M)
2424

2525
return ExaModel(c; prod = true), (x,), (s,)
2626
end
2727

2828
function exa_luksan_vlcek_model(backend, N; M = 1)
29-
m, vars, cons = _exa_luksan_vlcek_model(backend, N;M = M)
29+
m, vars, cons = _exa_luksan_vlcek_model(backend, N; M = M)
3030
return m
3131
end
3232

3333
function _jump_luksan_vlcek_model(backend, N; M = 1)
3434
jm = JuMP.Model()
3535

36-
JuMP.@variable(jm, x[i = 1:N, j=1:M], start = mod(i, 2) == 1 ? -1.2 : 1.0)
36+
JuMP.@variable(jm, x[i = 1:N, j = 1:M], start = mod(i, 2) == 1 ? -1.2 : 1.0)
3737
JuMP.@NLconstraint(
3838
jm,
39-
s[i = 1:N-2, j=1:M],
40-
3x[i+1,j]^3 + 2x[i+2,j] - 5 + sin(x[i+1,j] - x[i+2,j])sin(x[i+1,j] + x[i+2,j]) + 4x[i+1,j] -
41-
x[i,j]exp(x[i,j] - x[i+1,j]) - 3 == 0.0
39+
s[i = 1:N-2, j = 1:M],
40+
3x[i+1, j]^3 + 2x[i+2, j] - 5 +
41+
sin(x[i+1, j] - x[i+2, j])sin(x[i+1, j] + x[i+2, j]) +
42+
4x[i+1, j] - x[i, j]exp(x[i, j] - x[i+1, j]) - 3 == 0.0
43+
)
44+
JuMP.@NLobjective(
45+
jm,
46+
Min,
47+
sum(100(x[i-1, j]^2 - x[i, j])^2 + (x[i-1, j] - 1)^2 for i = 2:N, j = 1:M)
4248
)
43-
JuMP.@NLobjective(jm, Min, sum(100(x[i-1,j]^2 - x[i,j])^2 + (x[i-1,j] - 1)^2 for i = 2:N, j=1:M))
4449

4550
return jm, (x,), (s,)
4651
end

0 commit comments

Comments
 (0)