Skip to content

Commit 21da4b9

Browse files
authored
Add JuliaFormatter to all files (#2554)
1 parent 6126271 commit 21da4b9

File tree

5 files changed

+91
-32
lines changed

5 files changed

+91
-32
lines changed

.github/workflows/format_check.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ jobs:
2020
using Pkg
2121
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
2222
using JuliaFormatter
23-
format("src", verbose=true)
24-
format("test", verbose=true)
23+
format(".", verbose=true)
2524
out = String(read(Cmd(`git diff`)))
2625
if isempty(out)
2726
exit(0)

docs/make.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ const _PDF = findfirst(isequal("--pdf"), ARGS) !== nothing || _IS_GITHUB_ACTIONS
2121
# ==============================================================================
2222

2323
const _PAGES = [
24-
"Introduction" => [
25-
"index.md",
26-
"background/motivation.md",
27-
],
24+
"Introduction" => ["index.md", "background/motivation.md"],
2825
"Tutorials" => [
2926
"tutorials/example.md",
3027
"tutorials/implementing.md",
@@ -94,12 +91,12 @@ const _PAGES = [
9491

9592
function fix_release_line(
9693
line::String,
97-
url::String = "https://github.com/jump-dev/MathOptInterface.jl"
94+
url::String = "https://github.com/jump-dev/MathOptInterface.jl",
9895
)
9996
# (#XXXX) -> ([#XXXX](url/issue/XXXX))
10097
while (m = match(r"\(\#([0-9]+)\)", line)) !== nothing
101-
id = m.captures[1]
102-
line = replace(line, m.match => "([#$id]($url/issues/$id))")
98+
id = m.captures[1]
99+
line = replace(line, m.match => "([#$id]($url/issues/$id))")
103100
end
104101
# ## vX.Y.Z -> [vX.Y.Z](url/releases/tag/vX.Y.Z)
105102
while (m = match(r"\#\# (v[0-9]+.[0-9]+.[0-9]+)", line)) !== nothing

perf/bellman_ford.jl

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,58 @@ import MathOptInterface.Utilities as MOIU
1010

1111
# Model similar to SDPA format, it gives a good example because it does not
1212
# support a lot hence need a lot of bridges
13-
MOIU.@model(SDPAModel,
14-
(), (MOI.EqualTo,), (MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), (),
15-
(), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), ())
16-
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.GreaterThan{T}}) where {T} = false
17-
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.LessThan{T}}) where {T} = false
18-
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.EqualTo{T}}) where {T} = false
19-
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.Interval{T}}) where {T} = false
20-
MOI.supports_constraint(::SDPAModel, ::Type{MOI.VectorOfVariables}, ::Type{MOI.Reals}) = false
21-
MOI.supports(::SDPAModel{T}, ::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}}) where {T} = false
13+
MOIU.@model(
14+
SDPAModel,
15+
(),
16+
(MOI.EqualTo,),
17+
(MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
18+
(),
19+
(),
20+
(MOI.ScalarAffineFunction,),
21+
(MOI.VectorOfVariables,),
22+
()
23+
)
24+
function MOI.supports_constraint(
25+
::SDPAModel{T},
26+
::Type{MOI.VariableIndex},
27+
::Type{MOI.GreaterThan{T}},
28+
) where {T}
29+
return false
30+
end
31+
function MOI.supports_constraint(
32+
::SDPAModel{T},
33+
::Type{MOI.VariableIndex},
34+
::Type{MOI.LessThan{T}},
35+
) where {T}
36+
return false
37+
end
38+
function MOI.supports_constraint(
39+
::SDPAModel{T},
40+
::Type{MOI.VariableIndex},
41+
::Type{MOI.EqualTo{T}},
42+
) where {T}
43+
return false
44+
end
45+
function MOI.supports_constraint(
46+
::SDPAModel{T},
47+
::Type{MOI.VariableIndex},
48+
::Type{MOI.Interval{T}},
49+
) where {T}
50+
return false
51+
end
52+
function MOI.supports_constraint(
53+
::SDPAModel,
54+
::Type{MOI.VectorOfVariables},
55+
::Type{MOI.Reals},
56+
)
57+
return false
58+
end
59+
function MOI.supports(
60+
::SDPAModel{T},
61+
::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}},
62+
) where {T}
63+
return false
64+
end
2265
MOI.supports(::SDPAModel, ::MOI.ObjectiveFunction{MOI.VariableIndex}) = false
2366

2467
function interval_constraint()
@@ -31,7 +74,7 @@ function interval_constraint()
3174
MOI.Bridges._reset_bridge_graph($bridged)
3275
MOI.Bridges.node($bridged, $F, $S)
3376
end)
34-
display(@benchmark begin
77+
return display(@benchmark begin
3578
MOI.Bridges._reset_bridge_graph($bridged)
3679
MOI.Bridges.bridge_index($bridged, $F, $S)
3780
end)
@@ -48,7 +91,7 @@ function quadratic_objective()
4891
MOI.Bridges._reset_bridge_graph($bridged)
4992
MOI.Bridges.node($bridged, $F)
5093
end)
51-
display(@benchmark begin
94+
return display(@benchmark begin
5295
MOI.Bridges._reset_bridge_graph($bridged)
5396
MOI.Bridges.bridge_index($bridged, $F)
5497
end)

perf/cachingoptimizer.jl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,35 @@ using BenchmarkTools
1212
import MathOptInterface as MOI
1313
import MathOptInterface.Utilities as MOIU
1414

15-
@MOIU.model Model () (MOI.Interval,) () () () (MOI.ScalarAffineFunction,) () ()
15+
MOIU.@model Model () (MOI.Interval,) () () () (MOI.ScalarAffineFunction,) () ()
1616
optimizer = MOIU.MockOptimizer(Model{Float64}())
1717
caching_optimizer = MOIU.CachingOptimizer(Model{Float64}(), optimizer)
1818
MOIU.reset_optimizer(caching_optimizer) # detach optimizer
1919
v = MOI.add_variables(caching_optimizer, 2)
2020
cf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([0.0, 0.0], v), 0.0)
2121
c = MOI.add_constraint(caching_optimizer, cf, MOI.Interval(-Inf, 1.0))
22-
@btime MOI.set($caching_optimizer, $(MOI.ConstraintSet()), $c, $(MOI.Interval(0.0, 2.0)))
22+
@btime MOI.set(
23+
$caching_optimizer,
24+
$(MOI.ConstraintSet()),
25+
$c,
26+
$(MOI.Interval(0.0, 2.0)),
27+
)
2328
MOIU.attach_optimizer(caching_optimizer)
24-
@btime MOI.set($caching_optimizer, $(MOI.ConstraintSet()), $c, $(MOI.Interval(0.0, 2.0)))
25-
@btime MOI.set($(caching_optimizer.model_cache), $(MOI.ConstraintSet()), $c, $(MOI.Interval(0.0, 2.0)))
26-
@btime MOI.set($(caching_optimizer.optimizer), $(MOI.ConstraintSet()), $(caching_optimizer.model_to_optimizer_map[c]), $(MOI.Interval(0.0, 2.0)))
29+
@btime MOI.set(
30+
$caching_optimizer,
31+
$(MOI.ConstraintSet()),
32+
$c,
33+
$(MOI.Interval(0.0, 2.0)),
34+
)
35+
@btime MOI.set(
36+
$(caching_optimizer.model_cache),
37+
$(MOI.ConstraintSet()),
38+
$c,
39+
$(MOI.Interval(0.0, 2.0)),
40+
)
41+
@btime MOI.set(
42+
$(caching_optimizer.optimizer),
43+
$(MOI.ConstraintSet()),
44+
$(caching_optimizer.model_to_optimizer_map[c]),
45+
$(MOI.Interval(0.0, 2.0)),
46+
)

perf/time_to_first_solve/script.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ import MathOptInterface as MOI
1111
function example_diet(optimizer, bridge)
1212
category_data = [
1313
1800.0 2200.0
14-
91.0 Inf
15-
0.0 65.0
16-
0.0 1779.0
14+
91.0 Inf
15+
0.0 65.0
16+
0.0 1779.0
1717
]
1818
cost = [2.49, 2.89, 1.50, 1.89, 2.09, 1.99, 2.49, 0.89, 1.59]
1919
food_data = [
2020
410 24 26 730
2121
420 32 10 1190
2222
560 20 32 1800
23-
380 4 19 270
23+
380 4 19 270
2424
320 12 10 930
2525
320 15 12 820
2626
320 31 12 1230
27-
100 8 2.5 125
28-
330 8 10 180
27+
100 8 2.5 125
28+
330 8 10 180
2929
]
3030
bridge_model = if bridge
31-
MOI.instantiate(optimizer; with_bridge_type=Float64)
31+
MOI.instantiate(optimizer; with_bridge_type = Float64)
3232
else
3333
MOI.instantiate(optimizer)
3434
end

0 commit comments

Comments
 (0)