Skip to content

Commit 355a039

Browse files
authored
Update JuliaFormatter to v2 (#2731)
1 parent e57373b commit 355a039

26 files changed

+96
-111
lines changed

.github/workflows/format_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
shell: julia --color=yes {0}
1919
run: |
2020
using Pkg
21-
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
21+
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
2222
using JuliaFormatter
2323
format(".", verbose=true)
2424
out = String(read(Cmd(`git diff`)))

src/Bridges/Constraint/bridges/BinPackingToMILPBridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function MOI.Bridges.final_touch(
227227
end
228228
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
229229
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
230-
for xi in ret[1]::T:ret[2]::T
230+
for xi in (ret[1]::T):(ret[2]::T)
231231
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
232232
push!(bridge.variables, new_var)
233233
if !haskey(S, xi)

src/Bridges/Constraint/bridges/CircuitToMILPBridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function bridge_constraint(
5656
s::MOI.Circuit,
5757
) where {T,F<:Union{MOI.VectorOfVariables,MOI.VectorAffineFunction{T}}}
5858
n = MOI.dimension(s)
59-
z = [MOI.add_constrained_variable(model, MOI.ZeroOne())[1] for _ in 1:n^2]
59+
z = [MOI.add_constrained_variable(model, MOI.ZeroOne())[1] for _ in 1:(n^2)]
6060
Z = reshape(z, n, n)
6161
equal_to = MOI.ConstraintIndex{MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}[]
6262
for (i, x) in enumerate(MOI.Utilities.eachscalar(f))

src/Bridges/Constraint/bridges/CountDistinctToMILPBridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function _final_touch_general_case(
375375
end
376376
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
377377
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
378-
for xi in ret[1]::T:ret[2]::T
378+
for xi in (ret[1]::T):(ret[2]::T)
379379
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
380380
push!(bridge.variables, new_var)
381381
if !haskey(S, xi)

src/Bridges/Constraint/bridges/CountGreaterThanToMILPBridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function _add_unit_expansion(
214214
end
215215
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
216216
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
217-
for xi in ret[1]::T:ret[2]::T
217+
for xi in (ret[1]::T):(ret[2]::T)
218218
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
219219
push!(bridge.variables, new_var)
220220
if !haskey(S, xi)

src/Bridges/Constraint/bridges/LogDetBridge.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ function _extract_eigenvalues(
3131
f_scalars = MOI.Utilities.eachscalar(f)
3232
tu = [f_scalars[i] for i in 1:offset]
3333
n = MOI.Utilities.trimap(d, d)
34-
X = f_scalars[offset.+(1:n)]
34+
X = f_scalars[offset .+ (1:n)]
3535
N = MOI.Utilities.trimap(2d, 2d)
3636
Δ = MOI.add_variables(model, n)
3737
Z = [zero(MOI.ScalarAffineFunction{T}) for i in 1:(N-n)]
3838
for j in 1:d
3939
for i in j:d
40-
Z[MOI.Utilities.trimap(i, d + j)-n] = Δ[MOI.Utilities.trimap(i, j)]
40+
Z[MOI.Utilities.trimap(i, d+j)-n] = Δ[MOI.Utilities.trimap(i, j)]
4141
end
42-
Z[MOI.Utilities.trimap(d + j, d + j)-n] = Δ[MOI.Utilities.trimap(j, j)]
42+
Z[MOI.Utilities.trimap(d+j, d+j)-n] = Δ[MOI.Utilities.trimap(j, j)]
4343
end
4444
Y = MOI.Utilities.operate(vcat, T, X, MOI.Utilities.vectorize(Z))
4545
set = MOI.PositiveSemidefiniteConeTriangle(2d)

src/Bridges/Constraint/bridges/ReifiedCountDistinctToMILPBridge.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function MOI.get(
212212
)
213213
return MOI.ConstraintIndex{MOI.VariableIndex,MOI.ZeroOne}[
214214
MOI.ConstraintIndex{MOI.VariableIndex,MOI.ZeroOne}(x.value) for
215-
x in bridge.variables[1:end-2]
215+
x in bridge.variables[1:(end-2)]
216216
]
217217
end
218218

@@ -279,7 +279,7 @@ function MOI.Bridges.final_touch(
279279
end
280280
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
281281
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
282-
for xi in ret[1]::T:ret[2]::T
282+
for xi in (ret[1]::T):(ret[2]::T)
283283
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
284284
push!(bridge.variables, new_var)
285285
if !haskey(S, xi)

src/Bridges/Constraint/map.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function vector_of_variables_constraints(map::Map)
239239
Base.Iterators.Filter(
240240
i ->
241241
map.bridges[i] !== nothing &&
242-
map.constraint_types[i][1] == MOI.VectorOfVariables,
242+
map.constraint_types[i][1] == MOI.VectorOfVariables,
243243
eachindex(map.bridges),
244244
),
245245
)

src/Bridges/Variable/bridges/FreeBridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function MOI.get(
105105
) where {T}
106106
n = div(length(bridge.variables), 2)
107107
primal = MOI.get(model, attr, bridge.constraint)
108-
return primal[1:n] - primal[n.+(1:n)]
108+
return primal[1:n] - primal[n .+ (1:n)]
109109
end
110110

111111
# The transformation is x_free = [I -I] * x

src/Bridges/Variable/map.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ variables corresponding to `ci`.
553553
function function_for(map::Map, ci::MOI.ConstraintIndex{MOI.VectorOfVariables})
554554
index = map.vector_of_variables_map[-ci.value]
555555
variables = MOI.VariableIndex[]
556-
for i in index:-1:-length(map.bridges)
556+
for i in index:-1:(-length(map.bridges))
557557
vi = MOI.VariableIndex(i)
558558
if map.index_in_vector[-vi.value] == -1
559559
continue

src/Bridges/bridge_optimizer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ function _get_all_including_bridged(
735735
# function, so we may need to report multiple variables.
736736
push!(user_only_variables, user_variable)
737737
n = Variable.length_of_vector_of_variables(map, user_variable)
738-
for i in 1:n-1
738+
for i in 1:(n-1)
739739
push!(
740740
user_only_variables,
741741
MOI.VariableIndex(user_variable.value - i),
@@ -780,7 +780,7 @@ function _get_all_including_bridged(
780780
# `outer_variable` might represent the start of a VectorOfVariables
781781
# if multiple user-variables were bridged. Add them all.
782782
n = Variable.length_of_vector_of_variables(map, outer_variable)
783-
for i in 1:n-1
783+
for i in 1:(n-1)
784784
push!(ret, MOI.VariableIndex(outer_variable.value - i))
785785
end
786786
end

src/FileFormats/CBF/read.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,15 @@ function Base.read!(io::IO, model::Model)
360360
MOI.VectorAffineTerm{Float64}(4 - l, t) for
361361
l in 1:cone_dim for t in data.row_terms[row_idx+l]
362362
],
363-
data.row_constants[row_idx.+(3:-1:1)],
363+
data.row_constants[row_idx .+ (3:-1:1)],
364364
)
365365
else
366366
MOI.VectorAffineFunction(
367367
[
368368
MOI.VectorAffineTerm{Float64}(l, t) for l in 1:cone_dim
369369
for t in data.row_terms[row_idx+l]
370370
],
371-
data.row_constants[row_idx.+(1:cone_dim)],
371+
data.row_constants[row_idx .+ (1:cone_dim)],
372372
)
373373
end
374374
con_set = _cbf_to_moi_cone(data, cone_str, cone_dim)
@@ -386,7 +386,7 @@ function Base.read!(io::IO, model::Model)
386386
MOI.VectorAffineTerm{Float64}(l, t) for l in 1:cone_dim for
387387
t in data.psd_row_terms[row_start+l]
388388
],
389-
data.psd_row_constants[row_start.+(1:cone_dim)],
389+
data.psd_row_constants[row_start .+ (1:cone_dim)],
390390
)
391391
MOI.add_constraint(
392392
model,

src/FileFormats/MPS/MPS.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function Base.write(io::IO, model::Model)
221221
FileFormats.create_unique_names(
222222
model;
223223
warn = options.warn,
224-
replacements = Function[s->replace(s, ' ' => '_')],
224+
replacements = Function[s->replace(s, ' '=>'_')],
225225
)
226226
end
227227
variables = MOI.get(model, MOI.ListOfVariableIndices())

src/FileFormats/NL/NL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ function Base.write(io::IO, model::Model)
749749
if n_con > 0
750750
println(io, "k", length(model.x) - 1)
751751
total = 0
752-
for i in 1:length(model.order)-1
752+
for i in 1:(length(model.order)-1)
753753
total += model.x[model.order[i]].jacobian_count
754754
println(io, total)
755755
end

src/Nonlinear/ReverseAD/forward_over_reverse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function _eval_hessian_inner(
6060
num_products = size(ex.seed_matrix, 2) # number of hessian-vector products
6161
num_chunks = div(num_products, CHUNK)
6262
@assert size(ex.seed_matrix, 1) == length(local_to_global_idx)
63-
for k in 1:CHUNK:CHUNK*num_chunks
63+
for k in 1:CHUNK:(CHUNK*num_chunks)
6464
for r in 1:length(local_to_global_idx)
6565
# set up directional derivatives
6666
@inbounds idx = local_to_global_idx[r]

src/Nonlinear/ReverseAD/graph_tools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function _compute_hessian_sparsity(
258258
if !all(
259259
i ->
260260
input_linearity[children_arr[i]] == CONSTANT ||
261-
children_arr[i] == k,
261+
children_arr[i] == k,
262262
sibling_idx,
263263
)
264264
# at least one sibling isn't constant

src/Nonlinear/SymbolicAD/SymbolicAD.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ function derivative(f::MOI.ScalarNonlinearFunction, x::MOI.VariableIndex)
710710
)
711711
elseif f.head == :min
712712
g = derivative(f.args[end], x)
713-
for i in length(f.args)-1:-1:1
713+
for i in (length(f.args)-1):-1:1
714714
g = MOI.ScalarNonlinearFunction(
715715
:ifelse,
716716
Any[
@@ -723,7 +723,7 @@ function derivative(f::MOI.ScalarNonlinearFunction, x::MOI.VariableIndex)
723723
return g
724724
elseif f.head == :max
725725
g = derivative(f.args[end], x)
726-
for i in length(f.args)-1:-1:1
726+
for i in (length(f.args)-1):-1:1
727727
g = MOI.ScalarNonlinearFunction(
728728
:ifelse,
729729
Any[
@@ -896,7 +896,7 @@ function Base.show(io::IO, n::_Node)
896896
print(io, "# ", reinterpret(Float64, n.data))
897897
else
898898
type, op, nargs = _operator_to_type_id_nargs(n.operator)
899-
children = n.data .+ (0:nargs-1)
899+
children = n.data .+ (0:(nargs-1))
900900
print(io, "# $type(op = $op, children = $children)")
901901
end
902902
end

src/Nonlinear/operators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function _create_binary_switch(ids, exprs)
1717
:if,
1818
Expr(:call, :(<=), :id, ids[mid]),
1919
_create_binary_switch(ids[1:mid], exprs[1:mid]),
20-
_create_binary_switch(ids[mid+1:end], exprs[mid+1:end]),
20+
_create_binary_switch(ids[(mid+1):end], exprs[(mid+1):end]),
2121
)
2222
end
2323

src/Nonlinear/parse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function _parse_comparison_expression(
226226
x::Expr,
227227
parent_index::Int,
228228
)
229-
for k in 2:2:length(x.args)-1
229+
for k in 2:2:(length(x.args)-1)
230230
@assert x.args[k] == x.args[2] # don't handle a <= b >= c
231231
end
232232
operator_id = data.operators.comparison_operator_to_id[x.args[2]]

src/Test/test_conic.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ function test_conic_RotatedSecondOrderCone_INFEASIBLE_2(
26112611
@test (MOI.get(model, MOI.ConstraintDual(), c1), d, config)
26122612
@test (
26132613
MOI.get(model, MOI.ConstraintDual(), c2),
2614-
T[ub/√T(2), 1/√(2 * ub), -1],
2614+
T[ub/√T(2), 1/√(2*ub), -1],
26152615
config,
26162616
)
26172617
end
@@ -2642,7 +2642,7 @@ function setup_test(
26422642
-√ub / 2,
26432643
zeros(T, n - 1),
26442644
),
2645-
T[ub/√T(2), 1/√(2 * ub), -1],
2645+
T[ub/√T(2), 1/√(2*ub), -1],
26462646
],
26472647
),
26482648
)
@@ -4192,7 +4192,7 @@ function _test_conic_DualPowerCone_helper(
41924192
@test (MOI.get(model, MOI.VariablePrimal(), v), v_sol, config)
41934193
@test (
41944194
MOI.get(model, MOI.VariablePrimal(), x),
4195-
T[-exponent, -(1 - exponent)],
4195+
T[-exponent, -(1-exponent)],
41964196
config,
41974197
)
41984198
@test (MOI.get(model, MOI.ConstraintPrimal(), vc), v_sol, config)
@@ -4343,7 +4343,7 @@ function test_conic_RelativeEntropyCone(
43434343
if _supports(config, MOI.ConstraintDual)
43444344
@test (
43454345
MOI.get(model, MOI.ConstraintDual(), relentr),
4346-
T[1, 2, 3//5, log(T(1 // 2))-1, log(T(5 // 3))-1],
4346+
T[1, 2, 3//5, log(T(1//2))-1, log(T(5//3))-1],
43474347
config,
43484348
)
43494349
end
@@ -4362,7 +4362,7 @@ function setup_test(
43624362
mock,
43634363
[2 * log(T(2 // 1)) + 3 * log(T(3 // 5))],
43644364
(MOI.VectorAffineFunction{T}, MOI.RelativeEntropyCone) =>
4365-
[T[1, 2, 3//5, log(T(1 // 2))-1, log(T(5 // 3))-1]],
4365+
[T[1, 2, 3//5, log(T(1//2))-1, log(T(5//3))-1]],
43664366
),
43674367
)
43684368
return

src/Utilities/distance_to_set.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ function distance_to_set(
484484
) where {T<:Real}
485485
_check_dimension(x, set)
486486
p = sortperm(set.weights)
487-
pairs = collect(zip(p[1:end-1], p[2:end]))
487+
pairs = collect(zip(p[1:(end-1)], p[2:end]))
488488
_, k = findmax([abs(x[i]) + abs(x[j]) for (i, j) in pairs])
489489
elements = [x[i] for i in eachindex(x) if !(i in pairs[k])]
490490
return LinearAlgebra.norm(elements, 2)

src/Utilities/functions.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ function fill_variables(
19741974
::Int,
19751975
func::MOI.VectorOfVariables,
19761976
)
1977-
variables[offset.+(1:length(func.variables))] .= func.variables
1977+
variables[offset .+ (1:length(func.variables))] .= func.variables
19781978
return
19791979
end
19801980

@@ -2062,11 +2062,10 @@ function fill_terms(
20622062
func::MOI.VectorOfVariables,
20632063
) where {T}
20642064
n = number_of_affine_terms(T, func)
2065-
terms[offset.+(1:n)] .=
2066-
MOI.VectorAffineTerm.(
2067-
output_offset .+ (1:n),
2068-
MOI.ScalarAffineTerm.(one(T), func.variables),
2069-
)
2065+
terms[offset .+ (1:n)] .= MOI.VectorAffineTerm.(
2066+
output_offset .+ (1:n),
2067+
MOI.ScalarAffineTerm.(one(T), func.variables),
2068+
)
20702069
return
20712070
end
20722071

@@ -2077,7 +2076,7 @@ function fill_terms(
20772076
func::Union{MOI.ScalarAffineFunction{T},MOI.VectorAffineFunction{T}},
20782077
) where {T}
20792078
n = number_of_affine_terms(T, func)
2080-
terms[offset.+(1:n)] .= offset_term.(func.terms, output_offset)
2079+
terms[offset .+ (1:n)] .= offset_term.(func.terms, output_offset)
20812080
return
20822081
end
20832082

@@ -2088,7 +2087,7 @@ function fill_terms(
20882087
func::Union{MOI.ScalarQuadraticFunction{T},MOI.VectorQuadraticFunction{T}},
20892088
) where {T}
20902089
n = number_of_affine_terms(T, func)
2091-
terms[offset.+(1:n)] .= offset_term.(func.affine_terms, output_offset)
2090+
terms[offset .+ (1:n)] .= offset_term.(func.affine_terms, output_offset)
20922091
return
20932092
end
20942093

@@ -2115,7 +2114,7 @@ function fill_terms(
21152114
func::Union{MOI.ScalarQuadraticFunction{T},MOI.VectorQuadraticFunction{T}},
21162115
) where {T}
21172116
n = number_of_quadratic_terms(T, func)
2118-
terms[offset.+(1:n)] .= offset_term.(func.quadratic_terms, output_offset)
2117+
terms[offset .+ (1:n)] .= offset_term.(func.quadratic_terms, output_offset)
21192118
return
21202119
end
21212120

@@ -2173,7 +2172,7 @@ function fill_constant(
21732172
func::Union{MOI.VectorAffineFunction{T},MOI.VectorQuadraticFunction{T}},
21742173
) where {T}
21752174
n = MOI.output_dimension(func)
2176-
constant[offset.+(1:n)] .= func.constants
2175+
constant[offset .+ (1:n)] .= func.constants
21772176
return
21782177
end
21792178

test/FileFormats/MOF/MOF.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,9 +1419,11 @@ function test_integer_coefficients()
14191419
@test MOF.moi_to_object(f, names) == (
14201420
type = "ScalarQuadraticFunction",
14211421
affine_terms = [(coefficient = 3, variable = "x")],
1422-
quadratic_terms = [
1423-
(coefficient = 4, variable_1 = "x", variable_2 = "x"),
1424-
],
1422+
quadratic_terms = [(
1423+
coefficient = 4,
1424+
variable_1 = "x",
1425+
variable_2 = "x",
1426+
),],
14251427
constant = 4,
14261428
)
14271429
return

0 commit comments

Comments
 (0)