Skip to content

Commit 77799c6

Browse files
authored
Add JuliaFormatter (jump-dev#1289)
* Add CI check * Format codebase
1 parent 70b33f4 commit 77799c6

File tree

125 files changed

+11914
-4733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+11914
-4733
lines changed

.github/workflows/format_check.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: format-check
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-*
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: julia-actions/setup-julia@latest
14+
with:
15+
version: '1'
16+
- uses: actions/checkout@v1
17+
- name: Format check
18+
shell: julia --color=yes {0}
19+
run: |
20+
using Pkg
21+
Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.2"))
22+
using JuliaFormatter
23+
format("src", verbose=true)
24+
format("test", verbose=true)
25+
out = String(read(Cmd(`git diff`)))
26+
if isempty(out)
27+
exit(0)
28+
end
29+
@error "Some files have not been formatted !!!"
30+
write(stdout, out)
31+
exit(1)

src/Benchmarks/Benchmarks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ end
230230
MOI.add_constraints(
231231
model,
232232
[
233-
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, xi)], 0.0)
234-
for xi in x
233+
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, xi)], 0.0) for
234+
xi in x
235235
],
236236
MOI.LessThan.(1:1.0:10_000),
237237
)

src/Bridges/Constraint/function_conversion.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ function MOI.get(
1515
if invariant_under_function_conversion(attr)
1616
return MOI.get(model, attr, bridge.constraint)
1717
else
18-
throw(ArgumentError("Bridge of type `$(typeof(bridge))` does not support accessing the attribute `$attr` because `MOIB.Constraint.invariant_under_function_conversion($attr)` returns `false`."))
18+
throw(
19+
ArgumentError(
20+
"Bridge of type `$(typeof(bridge))` does not support accessing the attribute `$attr` because `MOIB.Constraint.invariant_under_function_conversion($attr)` returns `false`.",
21+
),
22+
)
1923
end
2024
end
2125

@@ -36,7 +40,11 @@ function MOI.set(
3640
if invariant_under_function_conversion(attr)
3741
return MOI.set(model, attr, bridge.constraint, value)
3842
else
39-
throw(ArgumentError("Bridge of type `$(typeof(bridge))` does not support setting the attribute `$attr` because `MOIB.Constraint.invariant_under_function_conversion($attr)` returns `false`."))
43+
throw(
44+
ArgumentError(
45+
"Bridge of type `$(typeof(bridge))` does not support setting the attribute `$attr` because `MOIB.Constraint.invariant_under_function_conversion($attr)` returns `false`.",
46+
),
47+
)
4048
end
4149
end
4250

src/Bridges/Constraint/geomean_to_relentr.jl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ function bridge_constraint(
2323
) where {T,F,G,H}
2424
f_scalars = MOIU.eachscalar(f)
2525
(y, nn_index) = MOI.add_constrained_variables(model, MOI.Nonnegatives(1))
26-
w_func = MOIU.vectorize(fill(
27-
MOIU.operate(+, T, f_scalars[1], MOI.SingleVariable(y[1])),
28-
MOI.dimension(s) - 1,
29-
))
26+
w_func = MOIU.vectorize(
27+
fill(
28+
MOIU.operate(+, T, f_scalars[1], MOI.SingleVariable(y[1])),
29+
MOI.dimension(s) - 1,
30+
),
31+
)
3032
relentr_func = MOIU.operate(
3133
vcat,
3234
T,
@@ -117,11 +119,9 @@ function MOI.get(
117119
::MOI.ConstraintFunction,
118120
bridge::GeoMeantoRelEntrBridge{T,F,G,H},
119121
) where {T,F,G,H}
120-
relentr_func = MOIU.eachscalar(MOI.get(
121-
model,
122-
MOI.ConstraintFunction(),
123-
bridge.relentr_index,
124-
))
122+
relentr_func = MOIU.eachscalar(
123+
MOI.get(model, MOI.ConstraintFunction(), bridge.relentr_index),
124+
)
125125
d = div(length(relentr_func) - 1, 2)
126126
u_func = MOIU.remove_variable(
127127
MOIU.operate(-, T, relentr_func[end], MOI.SingleVariable(bridge.y)),
@@ -137,11 +137,9 @@ function MOI.get(
137137
)
138138
return MOI.GeometricMeanCone(
139139
1 + div(
140-
MOI.dimension(MOI.get(
141-
model,
142-
MOI.ConstraintSet(),
143-
bridge.relentr_index,
144-
)) - 1,
140+
MOI.dimension(
141+
MOI.get(model, MOI.ConstraintSet(), bridge.relentr_index),
142+
) - 1,
145143
2,
146144
),
147145
)

src/Bridges/Constraint/indicator_sos.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ function MOI.get(
7878
attr::MOI.ConstraintSet,
7979
b::IndicatorSOS1Bridge,
8080
)
81-
return MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.get(
82-
model,
83-
attr,
84-
b.linear_constraint_index,
85-
),)
81+
return MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(
82+
MOI.get(model, attr, b.linear_constraint_index),
83+
)
8684
end
8785

8886
function MOI.get(

src/Bridges/Constraint/map.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ function add_key_for_bridge(
263263
set::MOI.AbstractScalarSet,
264264
)
265265
map.single_variable_constraints[(func.variable.value, typeof(set))] = bridge
266-
return MOI.ConstraintIndex{MOI.SingleVariable,typeof(set)}(func.variable.value)
266+
return MOI.ConstraintIndex{MOI.SingleVariable,typeof(set)}(
267+
func.variable.value,
268+
)
267269
end
268270

269271
"""

src/Bridges/Constraint/norm_spec_nuc_to_psd.jl

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,14 @@ function MOI.get(
8989
::MOI.ConstraintFunction,
9090
bridge::NormSpectralBridge{T,F,G},
9191
) where {T,F,G}
92-
psd_func = MOIU.eachscalar(MOI.get(
93-
model,
94-
MOI.ConstraintFunction(),
95-
bridge.psd_index,
96-
))
92+
psd_func = MOIU.eachscalar(
93+
MOI.get(model, MOI.ConstraintFunction(), bridge.psd_index),
94+
)
9795
t = psd_func[1]
9896
side_dim = bridge.row_dim + bridge.column_dim
9997
X = psd_func[[
100-
trimap(i, j) for j in 1:bridge.column_dim
101-
for i in (bridge.column_dim+1):side_dim
98+
trimap(i, j) for j in 1:bridge.column_dim for
99+
i in (bridge.column_dim+1):side_dim
102100
]]
103101
return MOIU.convert_approx(G, MOIU.operate(vcat, T, t, X))
104102
end
@@ -125,8 +123,8 @@ function MOI.get(
125123
t = primal[1]
126124
side_dim = bridge.row_dim + bridge.column_dim
127125
X = primal[[
128-
trimap(i, j) for j in 1:bridge.column_dim
129-
for i in (bridge.column_dim+1):side_dim
126+
trimap(i, j) for j in 1:bridge.column_dim for
127+
i in (bridge.column_dim+1):side_dim
130128
]]
131129
return vcat(t, X)
132130
end
@@ -314,11 +312,9 @@ function MOI.get(
314312
bridge::NormNuclearBridge{T,F,G,H},
315313
) where {T,F,G,H}
316314
ge_func = MOI.get(model, MOI.ConstraintFunction(), bridge.ge_index)
317-
psd_func = MOIU.eachscalar(MOI.get(
318-
model,
319-
MOI.ConstraintFunction(),
320-
bridge.psd_index,
321-
))
315+
psd_func = MOIU.eachscalar(
316+
MOI.get(model, MOI.ConstraintFunction(), bridge.psd_index),
317+
)
322318
column_dim = bridge.column_dim
323319
side_dim = bridge.row_dim + column_dim
324320
t = MOIU.operate(
@@ -334,8 +330,8 @@ function MOI.get(
334330
)
335331
t = MOIU.remove_variable(MOIU.remove_variable(t, bridge.U), bridge.V)
336332
X = psd_func[[
337-
trimap(i, j) for j in 1:bridge.column_dim
338-
for i in (bridge.column_dim+1):side_dim
333+
trimap(i, j) for j in 1:bridge.column_dim for
334+
i in (bridge.column_dim+1):side_dim
339335
]]
340336
return MOIU.convert_approx(H, MOIU.operate(vcat, T, t, X))
341337
end
@@ -363,8 +359,8 @@ function MOI.get(
363359
side_dim = bridge.row_dim + bridge.column_dim
364360
t = ge_primal + sum(psd_primal[trimap(i, i)] for i in 1:side_dim) / 2
365361
X = psd_primal[[
366-
trimap(i, j) for j in 1:bridge.column_dim
367-
for i in (bridge.column_dim+1):side_dim
362+
trimap(i, j) for j in 1:bridge.column_dim for
363+
i in (bridge.column_dim+1):side_dim
368364
]]
369365
return vcat(t, X)
370366
end
@@ -380,8 +376,8 @@ function MOI.get(
380376
side_dim = bridge.row_dim + bridge.column_dim
381377
X =
382378
2 * psd_dual[[
383-
trimap(i, j) for j in 1:bridge.column_dim
384-
for i in (bridge.column_dim+1):side_dim
379+
trimap(i, j) for j in 1:bridge.column_dim for
380+
i in (bridge.column_dim+1):side_dim
385381
]]
386382
return vcat(t, X)
387383
end

src/Bridges/Constraint/relentr_to_exp.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function bridge_constraint(
3939
) for i in 1:v_dim
4040
]
4141
exp_indices = [
42-
MOI.add_constraint(model, exp_func_i, MOI.ExponentialCone())
43-
for exp_func_i in exp_funcs
42+
MOI.add_constraint(model, exp_func_i, MOI.ExponentialCone()) for
43+
exp_func_i in exp_funcs
4444
]
4545
return RelativeEntropyBridge{T,F,G,H}(y, ge_index, exp_indices)
4646
end
@@ -131,11 +131,9 @@ function MOI.get(
131131
)
132132
w_start = 1 + length(bridge.y)
133133
for i in eachindex(bridge.y)
134-
exp_func_i = MOIU.eachscalar(MOI.get(
135-
model,
136-
MOI.ConstraintFunction(),
137-
bridge.exp_indices[i],
138-
))
134+
exp_func_i = MOIU.eachscalar(
135+
MOI.get(model, MOI.ConstraintFunction(), bridge.exp_indices[i]),
136+
)
139137
MOIU.operate_output_index!(-, T, 1, func, exp_func_i[1])
140138
MOIU.operate_output_index!(+, T, 1 + i, func, exp_func_i[3])
141139
MOIU.operate_output_index!(+, T, w_start + i, func, exp_func_i[2])

src/Bridges/Constraint/vectorize.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ function bridge_constraint(
2424
) where {T,F,S,G}
2525
scalar_const = MOI.constant(scalar_f, T)
2626
if !iszero(scalar_const)
27-
throw(MOI.ScalarFunctionConstantNotZero{
28-
typeof(scalar_const),
29-
G,
30-
typeof(set),
31-
}(
32-
scalar_const,
33-
))
27+
throw(
28+
MOI.ScalarFunctionConstantNotZero{
29+
typeof(scalar_const),
30+
G,
31+
typeof(set),
32+
}(
33+
scalar_const,
34+
),
35+
)
3436
end
3537
vector_f = convert(F, scalar_f)
3638
set_const = MOI.constant(set)

src/Bridges/Objective/bridge.jl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ function bridge_objective(
2222
::MOI.ModelLike,
2323
func::MOI.AbstractScalarFunction,
2424
)
25-
return throw(MOI.UnsupportedAttribute(MOI.ObjectiveFunction{typeof(func)}()))
25+
return throw(
26+
MOI.UnsupportedAttribute(MOI.ObjectiveFunction{typeof(func)}()),
27+
)
2628
end
2729

2830
"""
@@ -40,12 +42,14 @@ function MOI.set(
4042
bridge::AbstractBridge,
4143
::MOI.OptimizationSense,
4244
)
43-
return throw(ArgumentError(
44-
"Objective bridge of type `$(typeof(bridge))` does not support" *
45-
" modifying the objective sense. As a workaround, set the sense to" *
46-
" `MOI.FEASIBILITY_SENSE` to clear the objective function and" *
47-
" bridges.",
48-
))
45+
return throw(
46+
ArgumentError(
47+
"Objective bridge of type `$(typeof(bridge))` does not support" *
48+
" modifying the objective sense. As a workaround, set the sense to" *
49+
" `MOI.FEASIBILITY_SENSE` to clear the objective function and" *
50+
" bridges.",
51+
),
52+
)
4953
end
5054

5155
"""
@@ -60,10 +64,12 @@ function MOI.get(
6064
::MOI.ObjectiveFunction,
6165
bridge::AbstractBridge,
6266
)
63-
return throw(ArgumentError(
64-
"ObjectiveFunction bridge of type `$(typeof(bridge))` does not" *
65-
" support getting the objective function.",
66-
))
67+
return throw(
68+
ArgumentError(
69+
"ObjectiveFunction bridge of type `$(typeof(bridge))` does not" *
70+
" support getting the objective function.",
71+
),
72+
)
6773
end
6874

6975
"""
@@ -72,7 +78,11 @@ end
7278
Delete any variable or constraint added by `bridge`.
7379
"""
7480
function MOI.delete(::MOI.ModelLike, bridge::AbstractBridge)
75-
return throw(ArgumentError("`MOI.delete` not implemented for `ObjectiveFunction` bridges of type `$(typeof(bridge))`"))
81+
return throw(
82+
ArgumentError(
83+
"`MOI.delete` not implemented for `ObjectiveFunction` bridges of type `$(typeof(bridge))`",
84+
),
85+
)
7686
end
7787

7888
"""

0 commit comments

Comments
 (0)