Skip to content

Update JuliaFormatter to v2 #2731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
using JuliaFormatter
format(".", verbose=true)
out = String(read(Cmd(`git diff`)))
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/bridges/BinPackingToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function MOI.Bridges.final_touch(
end
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
for xi in ret[1]::T:ret[2]::T
for xi in (ret[1]::T):(ret[2]::T)
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
push!(bridge.variables, new_var)
if !haskey(S, xi)
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/bridges/CircuitToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function bridge_constraint(
s::MOI.Circuit,
) where {T,F<:Union{MOI.VectorOfVariables,MOI.VectorAffineFunction{T}}}
n = MOI.dimension(s)
z = [MOI.add_constrained_variable(model, MOI.ZeroOne())[1] for _ in 1:n^2]
z = [MOI.add_constrained_variable(model, MOI.ZeroOne())[1] for _ in 1:(n^2)]
Z = reshape(z, n, n)
equal_to = MOI.ConstraintIndex{MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}[]
for (i, x) in enumerate(MOI.Utilities.eachscalar(f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function _final_touch_general_case(
end
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
for xi in ret[1]::T:ret[2]::T
for xi in (ret[1]::T):(ret[2]::T)
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
push!(bridge.variables, new_var)
if !haskey(S, xi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function _add_unit_expansion(
end
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
for xi in ret[1]::T:ret[2]::T
for xi in (ret[1]::T):(ret[2]::T)
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
push!(bridge.variables, new_var)
if !haskey(S, xi)
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/Constraint/bridges/LogDetBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ function _extract_eigenvalues(
f_scalars = MOI.Utilities.eachscalar(f)
tu = [f_scalars[i] for i in 1:offset]
n = MOI.Utilities.trimap(d, d)
X = f_scalars[offset.+(1:n)]
X = f_scalars[offset .+ (1:n)]
N = MOI.Utilities.trimap(2d, 2d)
Δ = MOI.add_variables(model, n)
Z = [zero(MOI.ScalarAffineFunction{T}) for i in 1:(N-n)]
for j in 1:d
for i in j:d
Z[MOI.Utilities.trimap(i, d + j)-n] = Δ[MOI.Utilities.trimap(i, j)]
Z[MOI.Utilities.trimap(i, d+j)-n] = Δ[MOI.Utilities.trimap(i, j)]
end
Z[MOI.Utilities.trimap(d + j, d + j)-n] = Δ[MOI.Utilities.trimap(j, j)]
Z[MOI.Utilities.trimap(d+j, d+j)-n] = Δ[MOI.Utilities.trimap(j, j)]
end
Y = MOI.Utilities.operate(vcat, T, X, MOI.Utilities.vectorize(Z))
set = MOI.PositiveSemidefiniteConeTriangle(2d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function MOI.get(
)
return MOI.ConstraintIndex{MOI.VariableIndex,MOI.ZeroOne}[
MOI.ConstraintIndex{MOI.VariableIndex,MOI.ZeroOne}(x.value) for
x in bridge.variables[1:end-2]
x in bridge.variables[1:(end-2)]
]
end

Expand Down Expand Up @@ -279,7 +279,7 @@ function MOI.Bridges.final_touch(
end
unit_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
convex_f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
for xi in ret[1]::T:ret[2]::T
for xi in (ret[1]::T):(ret[2]::T)
new_var, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
push!(bridge.variables, new_var)
if !haskey(S, xi)
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function vector_of_variables_constraints(map::Map)
Base.Iterators.Filter(
i ->
map.bridges[i] !== nothing &&
map.constraint_types[i][1] == MOI.VectorOfVariables,
map.constraint_types[i][1] == MOI.VectorOfVariables,
eachindex(map.bridges),
),
)
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Variable/bridges/FreeBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function MOI.get(
) where {T}
n = div(length(bridge.variables), 2)
primal = MOI.get(model, attr, bridge.constraint)
return primal[1:n] - primal[n.+(1:n)]
return primal[1:n] - primal[n .+ (1:n)]
end

# The transformation is x_free = [I -I] * x
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Variable/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ variables corresponding to `ci`.
function function_for(map::Map, ci::MOI.ConstraintIndex{MOI.VectorOfVariables})
index = map.vector_of_variables_map[-ci.value]
variables = MOI.VariableIndex[]
for i in index:-1:-length(map.bridges)
for i in index:-1:(-length(map.bridges))
vi = MOI.VariableIndex(i)
if map.index_in_vector[-vi.value] == -1
continue
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ function _get_all_including_bridged(
# function, so we may need to report multiple variables.
push!(user_only_variables, user_variable)
n = Variable.length_of_vector_of_variables(map, user_variable)
for i in 1:n-1
for i in 1:(n-1)
push!(
user_only_variables,
MOI.VariableIndex(user_variable.value - i),
Expand Down Expand Up @@ -780,7 +780,7 @@ function _get_all_including_bridged(
# `outer_variable` might represent the start of a VectorOfVariables
# if multiple user-variables were bridged. Add them all.
n = Variable.length_of_vector_of_variables(map, outer_variable)
for i in 1:n-1
for i in 1:(n-1)
push!(ret, MOI.VariableIndex(outer_variable.value - i))
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/FileFormats/CBF/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,15 @@ function Base.read!(io::IO, model::Model)
MOI.VectorAffineTerm{Float64}(4 - l, t) for
l in 1:cone_dim for t in data.row_terms[row_idx+l]
],
data.row_constants[row_idx.+(3:-1:1)],
data.row_constants[row_idx .+ (3:-1:1)],
)
else
MOI.VectorAffineFunction(
[
MOI.VectorAffineTerm{Float64}(l, t) for l in 1:cone_dim
for t in data.row_terms[row_idx+l]
],
data.row_constants[row_idx.+(1:cone_dim)],
data.row_constants[row_idx .+ (1:cone_dim)],
)
end
con_set = _cbf_to_moi_cone(data, cone_str, cone_dim)
Expand All @@ -386,7 +386,7 @@ function Base.read!(io::IO, model::Model)
MOI.VectorAffineTerm{Float64}(l, t) for l in 1:cone_dim for
t in data.psd_row_terms[row_start+l]
],
data.psd_row_constants[row_start.+(1:cone_dim)],
data.psd_row_constants[row_start .+ (1:cone_dim)],
)
MOI.add_constraint(
model,
Expand Down
2 changes: 1 addition & 1 deletion src/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function Base.write(io::IO, model::Model)
FileFormats.create_unique_names(
model;
warn = options.warn,
replacements = Function[s->replace(s, ' ' => '_')],
replacements = Function[s->replace(s, ' '=>'_')],
)
end
variables = MOI.get(model, MOI.ListOfVariableIndices())
Expand Down
2 changes: 1 addition & 1 deletion src/FileFormats/NL/NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ function Base.write(io::IO, model::Model)
if n_con > 0
println(io, "k", length(model.x) - 1)
total = 0
for i in 1:length(model.order)-1
for i in 1:(length(model.order)-1)
total += model.x[model.order[i]].jacobian_count
println(io, total)
end
Expand Down
2 changes: 1 addition & 1 deletion src/Nonlinear/ReverseAD/forward_over_reverse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function _eval_hessian_inner(
num_products = size(ex.seed_matrix, 2) # number of hessian-vector products
num_chunks = div(num_products, CHUNK)
@assert size(ex.seed_matrix, 1) == length(local_to_global_idx)
for k in 1:CHUNK:CHUNK*num_chunks
for k in 1:CHUNK:(CHUNK*num_chunks)
for r in 1:length(local_to_global_idx)
# set up directional derivatives
@inbounds idx = local_to_global_idx[r]
Expand Down
2 changes: 1 addition & 1 deletion src/Nonlinear/ReverseAD/graph_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function _compute_hessian_sparsity(
if !all(
i ->
input_linearity[children_arr[i]] == CONSTANT ||
children_arr[i] == k,
children_arr[i] == k,
sibling_idx,
)
# at least one sibling isn't constant
Expand Down
6 changes: 3 additions & 3 deletions src/Nonlinear/SymbolicAD/SymbolicAD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ function derivative(f::MOI.ScalarNonlinearFunction, x::MOI.VariableIndex)
)
elseif f.head == :min
g = derivative(f.args[end], x)
for i in length(f.args)-1:-1:1
for i in (length(f.args)-1):-1:1
g = MOI.ScalarNonlinearFunction(
:ifelse,
Any[
Expand All @@ -723,7 +723,7 @@ function derivative(f::MOI.ScalarNonlinearFunction, x::MOI.VariableIndex)
return g
elseif f.head == :max
g = derivative(f.args[end], x)
for i in length(f.args)-1:-1:1
for i in (length(f.args)-1):-1:1
g = MOI.ScalarNonlinearFunction(
:ifelse,
Any[
Expand Down Expand Up @@ -896,7 +896,7 @@ function Base.show(io::IO, n::_Node)
print(io, "# ", reinterpret(Float64, n.data))
else
type, op, nargs = _operator_to_type_id_nargs(n.operator)
children = n.data .+ (0:nargs-1)
children = n.data .+ (0:(nargs-1))
print(io, "# $type(op = $op, children = $children)")
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/Nonlinear/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function _create_binary_switch(ids, exprs)
:if,
Expr(:call, :(<=), :id, ids[mid]),
_create_binary_switch(ids[1:mid], exprs[1:mid]),
_create_binary_switch(ids[mid+1:end], exprs[mid+1:end]),
_create_binary_switch(ids[(mid+1):end], exprs[(mid+1):end]),
)
end

Expand Down
2 changes: 1 addition & 1 deletion src/Nonlinear/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function _parse_comparison_expression(
x::Expr,
parent_index::Int,
)
for k in 2:2:length(x.args)-1
for k in 2:2:(length(x.args)-1)
@assert x.args[k] == x.args[2] # don't handle a <= b >= c
end
operator_id = data.operators.comparison_operator_to_id[x.args[2]]
Expand Down
10 changes: 5 additions & 5 deletions src/Test/test_conic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ function test_conic_RotatedSecondOrderCone_INFEASIBLE_2(
@test ≈(MOI.get(model, MOI.ConstraintDual(), c1), d, config)
@test ≈(
MOI.get(model, MOI.ConstraintDual(), c2),
T[√ub/√T(2), 1/√(2 * ub), -1],
T[√ub/√T(2), 1/√(2*ub), -1],
config,
)
end
Expand Down Expand Up @@ -2642,7 +2642,7 @@ function setup_test(
-√ub / 2,
zeros(T, n - 1),
),
T[√ub/√T(2), 1/√(2 * ub), -1],
T[√ub/√T(2), 1/√(2*ub), -1],
],
),
)
Expand Down Expand Up @@ -4192,7 +4192,7 @@ function _test_conic_DualPowerCone_helper(
@test ≈(MOI.get(model, MOI.VariablePrimal(), v), v_sol, config)
@test ≈(
MOI.get(model, MOI.VariablePrimal(), x),
T[-exponent, -(1 - exponent)],
T[-exponent, -(1-exponent)],
config,
)
@test ≈(MOI.get(model, MOI.ConstraintPrimal(), vc), v_sol, config)
Expand Down Expand Up @@ -4343,7 +4343,7 @@ function test_conic_RelativeEntropyCone(
if _supports(config, MOI.ConstraintDual)
@test ≈(
MOI.get(model, MOI.ConstraintDual(), relentr),
T[1, 2, 3//5, log(T(1 // 2))-1, log(T(5 // 3))-1],
T[1, 2, 3//5, log(T(1//2))-1, log(T(5//3))-1],
config,
)
end
Expand All @@ -4362,7 +4362,7 @@ function setup_test(
mock,
[2 * log(T(2 // 1)) + 3 * log(T(3 // 5))],
(MOI.VectorAffineFunction{T}, MOI.RelativeEntropyCone) =>
[T[1, 2, 3//5, log(T(1 // 2))-1, log(T(5 // 3))-1]],
[T[1, 2, 3//5, log(T(1//2))-1, log(T(5//3))-1]],
),
)
return
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/distance_to_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
) where {T<:Real}
_check_dimension(x, set)
p = sortperm(set.weights)
pairs = collect(zip(p[1:end-1], p[2:end]))
pairs = collect(zip(p[1:(end-1)], p[2:end]))

Check warning on line 487 in src/Utilities/distance_to_set.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/distance_to_set.jl#L487

Added line #L487 was not covered by tests
_, k = findmax([abs(x[i]) + abs(x[j]) for (i, j) in pairs])
elements = [x[i] for i in eachindex(x) if !(i in pairs[k])]
return LinearAlgebra.norm(elements, 2)
Expand Down
19 changes: 9 additions & 10 deletions src/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ function fill_variables(
::Int,
func::MOI.VectorOfVariables,
)
variables[offset.+(1:length(func.variables))] .= func.variables
variables[offset .+ (1:length(func.variables))] .= func.variables
return
end

Expand Down Expand Up @@ -2062,11 +2062,10 @@ function fill_terms(
func::MOI.VectorOfVariables,
) where {T}
n = number_of_affine_terms(T, func)
terms[offset.+(1:n)] .=
MOI.VectorAffineTerm.(
output_offset .+ (1:n),
MOI.ScalarAffineTerm.(one(T), func.variables),
)
terms[offset .+ (1:n)] .= MOI.VectorAffineTerm.(
output_offset .+ (1:n),
MOI.ScalarAffineTerm.(one(T), func.variables),
)
return
end

Expand All @@ -2077,7 +2076,7 @@ function fill_terms(
func::Union{MOI.ScalarAffineFunction{T},MOI.VectorAffineFunction{T}},
) where {T}
n = number_of_affine_terms(T, func)
terms[offset.+(1:n)] .= offset_term.(func.terms, output_offset)
terms[offset .+ (1:n)] .= offset_term.(func.terms, output_offset)
return
end

Expand All @@ -2088,7 +2087,7 @@ function fill_terms(
func::Union{MOI.ScalarQuadraticFunction{T},MOI.VectorQuadraticFunction{T}},
) where {T}
n = number_of_affine_terms(T, func)
terms[offset.+(1:n)] .= offset_term.(func.affine_terms, output_offset)
terms[offset .+ (1:n)] .= offset_term.(func.affine_terms, output_offset)
return
end

Expand All @@ -2115,7 +2114,7 @@ function fill_terms(
func::Union{MOI.ScalarQuadraticFunction{T},MOI.VectorQuadraticFunction{T}},
) where {T}
n = number_of_quadratic_terms(T, func)
terms[offset.+(1:n)] .= offset_term.(func.quadratic_terms, output_offset)
terms[offset .+ (1:n)] .= offset_term.(func.quadratic_terms, output_offset)
return
end

Expand Down Expand Up @@ -2173,7 +2172,7 @@ function fill_constant(
func::Union{MOI.VectorAffineFunction{T},MOI.VectorQuadraticFunction{T}},
) where {T}
n = MOI.output_dimension(func)
constant[offset.+(1:n)] .= func.constants
constant[offset .+ (1:n)] .= func.constants
return
end

Expand Down
8 changes: 5 additions & 3 deletions test/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1419,9 +1419,11 @@ function test_integer_coefficients()
@test MOF.moi_to_object(f, names) == (
type = "ScalarQuadraticFunction",
affine_terms = [(coefficient = 3, variable = "x")],
quadratic_terms = [
(coefficient = 4, variable_1 = "x", variable_2 = "x"),
],
quadratic_terms = [(
coefficient = 4,
variable_1 = "x",
variable_2 = "x",
),],
constant = 4,
)
return
Expand Down
Loading
Loading