diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index c4482c2299..c0435cadd7 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -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`))) diff --git a/src/Bridges/Constraint/bridges/BinPackingToMILPBridge.jl b/src/Bridges/Constraint/bridges/BinPackingToMILPBridge.jl index 413e92c9b7..5c450bda9f 100644 --- a/src/Bridges/Constraint/bridges/BinPackingToMILPBridge.jl +++ b/src/Bridges/Constraint/bridges/BinPackingToMILPBridge.jl @@ -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) diff --git a/src/Bridges/Constraint/bridges/CircuitToMILPBridge.jl b/src/Bridges/Constraint/bridges/CircuitToMILPBridge.jl index c95305d580..0a35233ee1 100644 --- a/src/Bridges/Constraint/bridges/CircuitToMILPBridge.jl +++ b/src/Bridges/Constraint/bridges/CircuitToMILPBridge.jl @@ -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)) diff --git a/src/Bridges/Constraint/bridges/CountDistinctToMILPBridge.jl b/src/Bridges/Constraint/bridges/CountDistinctToMILPBridge.jl index 977e542f73..3e3facdc1f 100644 --- a/src/Bridges/Constraint/bridges/CountDistinctToMILPBridge.jl +++ b/src/Bridges/Constraint/bridges/CountDistinctToMILPBridge.jl @@ -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) diff --git a/src/Bridges/Constraint/bridges/CountGreaterThanToMILPBridge.jl b/src/Bridges/Constraint/bridges/CountGreaterThanToMILPBridge.jl index 5146b896e4..8d7370ab8a 100644 --- a/src/Bridges/Constraint/bridges/CountGreaterThanToMILPBridge.jl +++ b/src/Bridges/Constraint/bridges/CountGreaterThanToMILPBridge.jl @@ -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) diff --git a/src/Bridges/Constraint/bridges/LogDetBridge.jl b/src/Bridges/Constraint/bridges/LogDetBridge.jl index c35a643395..b72714dfef 100644 --- a/src/Bridges/Constraint/bridges/LogDetBridge.jl +++ b/src/Bridges/Constraint/bridges/LogDetBridge.jl @@ -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) diff --git a/src/Bridges/Constraint/bridges/ReifiedCountDistinctToMILPBridge.jl b/src/Bridges/Constraint/bridges/ReifiedCountDistinctToMILPBridge.jl index 49c5dc6683..ffaf89f1d2 100644 --- a/src/Bridges/Constraint/bridges/ReifiedCountDistinctToMILPBridge.jl +++ b/src/Bridges/Constraint/bridges/ReifiedCountDistinctToMILPBridge.jl @@ -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 @@ -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) diff --git a/src/Bridges/Constraint/map.jl b/src/Bridges/Constraint/map.jl index 370f36c380..b5926b690b 100644 --- a/src/Bridges/Constraint/map.jl +++ b/src/Bridges/Constraint/map.jl @@ -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), ), ) diff --git a/src/Bridges/Variable/bridges/FreeBridge.jl b/src/Bridges/Variable/bridges/FreeBridge.jl index 3101fad948..ad39bf65e3 100644 --- a/src/Bridges/Variable/bridges/FreeBridge.jl +++ b/src/Bridges/Variable/bridges/FreeBridge.jl @@ -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 diff --git a/src/Bridges/Variable/map.jl b/src/Bridges/Variable/map.jl index a1efd6d047..806d4b939a 100644 --- a/src/Bridges/Variable/map.jl +++ b/src/Bridges/Variable/map.jl @@ -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 diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index fa2638e7a0..fff102820a 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -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), @@ -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 diff --git a/src/FileFormats/CBF/read.jl b/src/FileFormats/CBF/read.jl index 380c8fd9b0..7bf9bc5376 100644 --- a/src/FileFormats/CBF/read.jl +++ b/src/FileFormats/CBF/read.jl @@ -360,7 +360,7 @@ 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( @@ -368,7 +368,7 @@ function Base.read!(io::IO, model::Model) 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) @@ -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, diff --git a/src/FileFormats/MPS/MPS.jl b/src/FileFormats/MPS/MPS.jl index ae2512dfff..c9ea639fae 100644 --- a/src/FileFormats/MPS/MPS.jl +++ b/src/FileFormats/MPS/MPS.jl @@ -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()) diff --git a/src/FileFormats/NL/NL.jl b/src/FileFormats/NL/NL.jl index d58ddfa2f9..d59f1bdedb 100644 --- a/src/FileFormats/NL/NL.jl +++ b/src/FileFormats/NL/NL.jl @@ -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 diff --git a/src/Nonlinear/ReverseAD/forward_over_reverse.jl b/src/Nonlinear/ReverseAD/forward_over_reverse.jl index 4ef7ce08c4..bcc1f86a98 100644 --- a/src/Nonlinear/ReverseAD/forward_over_reverse.jl +++ b/src/Nonlinear/ReverseAD/forward_over_reverse.jl @@ -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] diff --git a/src/Nonlinear/ReverseAD/graph_tools.jl b/src/Nonlinear/ReverseAD/graph_tools.jl index b52f305ac5..7e9c366c26 100644 --- a/src/Nonlinear/ReverseAD/graph_tools.jl +++ b/src/Nonlinear/ReverseAD/graph_tools.jl @@ -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 diff --git a/src/Nonlinear/SymbolicAD/SymbolicAD.jl b/src/Nonlinear/SymbolicAD/SymbolicAD.jl index 169fed6218..c68ff58cc0 100644 --- a/src/Nonlinear/SymbolicAD/SymbolicAD.jl +++ b/src/Nonlinear/SymbolicAD/SymbolicAD.jl @@ -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[ @@ -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[ @@ -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 diff --git a/src/Nonlinear/operators.jl b/src/Nonlinear/operators.jl index 4733609482..c4b53de468 100644 --- a/src/Nonlinear/operators.jl +++ b/src/Nonlinear/operators.jl @@ -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 diff --git a/src/Nonlinear/parse.jl b/src/Nonlinear/parse.jl index 4b0d5e6ab8..66dee02eab 100644 --- a/src/Nonlinear/parse.jl +++ b/src/Nonlinear/parse.jl @@ -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]] diff --git a/src/Test/test_conic.jl b/src/Test/test_conic.jl index 73d3706052..816597de98 100644 --- a/src/Test/test_conic.jl +++ b/src/Test/test_conic.jl @@ -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 @@ -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], ], ), ) @@ -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) @@ -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 @@ -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 diff --git a/src/Utilities/distance_to_set.jl b/src/Utilities/distance_to_set.jl index 12655c4222..5acd342943 100644 --- a/src/Utilities/distance_to_set.jl +++ b/src/Utilities/distance_to_set.jl @@ -484,7 +484,7 @@ function distance_to_set( ) 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])) _, 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) diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index df8194ec1e..f5483f8b83 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/FileFormats/MOF/MOF.jl b/test/FileFormats/MOF/MOF.jl index 51e4458b5c..708ba4de2d 100644 --- a/test/FileFormats/MOF/MOF.jl +++ b/test/FileFormats/MOF/MOF.jl @@ -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 diff --git a/test/Nonlinear/SymbolicAD.jl b/test/Nonlinear/SymbolicAD.jl index 9b53473982..2966283468 100644 --- a/test/Nonlinear/SymbolicAD.jl +++ b/test/Nonlinear/SymbolicAD.jl @@ -44,8 +44,8 @@ function test_derivative() 2.0*x+y+2.0=>2.0, 2.0*x+y+z+2.0=>2.0, # derivative(f::MOI.ScalarQuadraticFunction{T}, x::MOI.VariableIndex) - convert(MOI.ScalarQuadraticFunction{Float64}, 1.0 * x)=>1.0, - convert(MOI.ScalarQuadraticFunction{Float64}, 1.0 * x + 0.0 * y)=>1.0, + convert(MOI.ScalarQuadraticFunction{Float64}, 1.0*x)=>1.0, + convert(MOI.ScalarQuadraticFunction{Float64}, 1.0*x+0.0*y)=>1.0, 1.0*x*y=>y, 1.0*y*x=>y, 1.0*x*x=>2.0*x, @@ -70,7 +70,7 @@ function test_derivative() sin_x=>cos_x, cos_x=>op(:-, sin_x), op(:log, x)=>op(:/, 1, x), - op(:log, 2.0 * x)=>op(:*, op(:/, 1, 2.0 * x), 2.0), + op(:log, 2.0*x)=>op(:*, op(:/, 1, 2.0*x), 2.0), # f.head == :+ op(:+, sin_x, cos_x)=>op(:-, cos_x, sin_x), # f.head == :- @@ -86,11 +86,7 @@ function test_derivative() :^, x, x, - )=>op( - :+, - op(:*, x, op(:^, x, x - 1)), - op(:*, op(:^, x, x), op(:log, x)), - ), + )=>op(:+, op(:*, x, op(:^, x, x-1)), op(:*, op(:^, x, x), op(:log, x))), op(:^, x, 3)=>3.0*x*x, # :/ op(:/, x, 2)=>0.5, @@ -104,7 +100,7 @@ function test_derivative() op(:^, op(:+, x, 1), 2), ), # :ifelse - op(:ifelse, z, 1.0 * x * x, x)=>op(:ifelse, z, 2.0 * x, 1.0), + op(:ifelse, z, 1.0*x*x, x)=>op(:ifelse, z, 2.0*x, 1.0), # :atan op( :atan, @@ -119,14 +115,14 @@ function test_derivative() op( :min, x, - 1.0 * x * x, - )=>op(:ifelse, op(:(<=), x, op(:min, x, 1.0 * x * x)), 1.0, 2.0 * x), + 1.0*x*x, + )=>op(:ifelse, op(:(<=), x, op(:min, x, 1.0*x*x)), 1.0, 2.0*x), # :max op( :max, x, - 1.0 * x * x, - )=>op(:ifelse, op(:(>=), x, op(:max, x, 1.0 * x * x)), 1.0, 2.0 * x), + 1.0*x*x, + )=>op(:ifelse, op(:(>=), x, op(:max, x, 1.0*x*x)), 1.0, 2.0*x), # comparisons op(:(>=), x, y)=>false, op(:(==), x, y)=>false, @@ -164,11 +160,8 @@ function test_variable() y+1.0+z=>[y, z], # ::QuadExpr zero(MOI.ScalarQuadraticFunction{Float64})=>[], - convert(MOI.ScalarQuadraticFunction{Float64}, 1.0 * x + 1.0)=>[x], - convert( - MOI.ScalarQuadraticFunction{Float64}, - 1.0 * x + 1.0 + y, - )=>[x, y], + convert(MOI.ScalarQuadraticFunction{Float64}, 1.0*x+1.0)=>[x], + convert(MOI.ScalarQuadraticFunction{Float64}, 1.0*x+1.0+y)=>[x, y], 1.0*x*x=>[x], 1.0*x*x+x=>[x], 1.0*x*x+y=>[x, y], @@ -176,7 +169,7 @@ function test_variable() 1.0*y*x=>[x, y], # ::NonlinearExpr op(:sin, x)=>[x], - op(:sin, 1.0 * x + y)=>[x, y], + op(:sin, 1.0*x+y)=>[x, y], op(:*, op(:sin, x), op(:sin, y))=>[x, y], op(:^, op(:log, x), 2)=>[x], ] @@ -716,7 +709,7 @@ function test_simplify_if_quadratic() for (f, ret) in Any[ # Constants op(:*, 2)=>2, - op(:*, 2 // 3)=>2/3, + op(:*, 2//3)=>2/3, op(:*, 2, 3)=>6, op(:+, 2, 3)=>5, op(:-, 2)=>-2, @@ -730,27 +723,27 @@ function test_simplify_if_quadratic() op(:+, x, x)=>2.0*x, op(:+, x, 2, x)=>2.0*x+2.0, op(:+, x, 2, op(:+, x))=>2.0*x+2.0, - op(:+, 1.0 * x, 1.0 * x + 2.0)=>2.0*x+2.0, - op(:-, 1.0 * x + 2.0)=>-1.0*x-2.0, - op(:*, 2, 1.0 * x + 2.0, 3)=>6.0*x+12.0, + op(:+, 1.0*x, 1.0*x+2.0)=>2.0*x+2.0, + op(:-, 1.0*x+2.0)=>-1.0*x-2.0, + op(:*, 2, 1.0*x+2.0, 3)=>6.0*x+12.0, # Quadratic - op(:+, 1.0 * x * x)=>1.0*x*x, + op(:+, 1.0*x*x)=>1.0*x*x, op(:*, 2, x, 3, x)=>6.0*x*x, - op(:*, 2, x, 3, 1.0 * x)=>6.0*x*x, - op(:*, 2, x, 3, 1.0 * x + 2.0)=>6.0*x*x+12.0*x, - op(:*, 2, 1.0 * x + 2.0, 3, x)=>6.0*x*x+12.0*x, - op(:*, 1.0 * x + 2.0, 1.0 * x)=>1.0*x*x+2.0*x, - op(:*, 1.0 * x + 2.0, 1.0 * x + 1.0)=>1.0*x*x+3.0*x+2.0, + op(:*, 2, x, 3, 1.0*x)=>6.0*x*x, + op(:*, 2, x, 3, 1.0*x+2.0)=>6.0*x*x+12.0*x, + op(:*, 2, 1.0*x+2.0, 3, x)=>6.0*x*x+12.0*x, + op(:*, 1.0*x+2.0, 1.0*x)=>1.0*x*x+2.0*x, + op(:*, 1.0*x+2.0, 1.0*x+1.0)=>1.0*x*x+3.0*x+2.0, # Power op(:^, x, 2)=>1.0*x*x, - op(:^, 1.0 * x, 2)=>1.0*x*x, - op(:^, 1.0 * x + 1.0, 2)=>1.0*x*x+2.0*x+1.0, - op(:^, -2.0 * x - 2.0, 2)=>4.0*x*x+8.0*x+4.0, + op(:^, 1.0*x, 2)=>1.0*x*x, + op(:^, 1.0*x+1.0, 2)=>1.0*x*x+2.0*x+1.0, + op(:^, -2.0*x-2.0, 2)=>4.0*x*x+8.0*x+4.0, # Divide op(:/, x, 2)=>0.5*x, - op(:/, 1.0 * x, 2)=>0.5*x, - op(:/, 2.0 * x, 2)=>x, - op(:/, 2.0 * x * x, 2)=>1.0*x*x, + op(:/, 1.0*x, 2)=>0.5*x, + op(:/, 2.0*x, 2)=>x, + op(:/, 2.0*x*x, 2)=>1.0*x*x, # Early termination because not affine op(:+, op(:sin, x))=>nothing, op(:-, op(:sin, x))=>nothing, @@ -758,10 +751,10 @@ function test_simplify_if_quadratic() op(:-, x, op(:sin, x))=>nothing, op(:*, 2, 3, op(:sin, x))=>nothing, op(:log, x)=>nothing, - op(:+, big(1) * x * x, big(2))=>nothing, - op(:+, big(1) * x, big(2))=>nothing, + op(:+, big(1)*x*x, big(2))=>nothing, + op(:+, big(1)*x, big(2))=>nothing, op(:+, x, big(2))=>nothing, - op(:+, x, 1 + 2im)=>nothing, + op(:+, x, 1+2im)=>nothing, ] @test SymbolicAD._simplify_if_quadratic!(f) ≈ something(ret, f) end diff --git a/test/Utilities/functions.jl b/test/Utilities/functions.jl index c53a0d9a27..1d59ee3773 100644 --- a/test/Utilities/functions.jl +++ b/test/Utilities/functions.jl @@ -113,14 +113,13 @@ function test_Vectorization_operate_vcat() Int, ) == MOI.VectorAffineFunction{Int} F = MOI.Utilities.operate(vcat, Int, w, f, v, 3, g, x, -4) - expected_terms = - MOI.VectorAffineTerm.( - [1, 2, 2, 3, 4, 8, 6, 9], - MOI.ScalarAffineTerm.( - [1, 2, 4, 1, 1, 5, 2, 1], - [w, x, z, y, w, y, x, x], - ), - ) + expected_terms = MOI.VectorAffineTerm.( + [1, 2, 2, 3, 4, 8, 6, 9], + MOI.ScalarAffineTerm.( + [1, 2, 4, 1, 1, 5, 2, 1], + [w, x, z, y, w, y, x, x], + ), + ) expected_constants = [0, 5, 0, 0, 3, 3, 1, 4, 0, -4] F = MOI.Utilities.operate(vcat, Int, w, f, v, 3, g, x, -4) @test F.terms == expected_terms @@ -417,8 +416,7 @@ end function test_Conversion_VectorOfVariables_VectorAffineFunction() f = MOI.VectorAffineFunction{Int}(MOI.VectorOfVariables([z, x, y])) @test f isa MOI.VectorAffineFunction{Int} - @test f.terms == - MOI.VectorAffineTerm.( + @test f.terms == MOI.VectorAffineTerm.( 1:3, MOI.ScalarAffineTerm.(ones(Int, 3), [z, x, y]), ) @@ -474,16 +472,14 @@ function test_indexing_on_VectorAffineFunction() @test g.constant == 5 h = it[[3, 1]] @test h isa MOI.VectorAffineFunction - @test sort(h.terms, by = t -> t.output_index) == - MOI.VectorAffineTerm.( + @test sort(h.terms, by = t -> t.output_index) == MOI.VectorAffineTerm.( [1, 1, 2, 2, 2], MOI.ScalarAffineTerm.([2, 6, 7, 1, 4], [z, x, y, z, x]), ) @test MOI.Utilities.constant_vector(h) == [5, 2] F = MOI.Utilities.operate(vcat, Int, it[[1, 2]], it[3]) @test F isa MOI.VectorAffineFunction{Int} - @test sort(F.terms, by = t -> t.output_index) == - MOI.VectorAffineTerm.( + @test sort(F.terms, by = t -> t.output_index) == MOI.VectorAffineTerm.( [1, 1, 1, 2, 2, 2, 2, 3, 3], MOI.ScalarAffineTerm.( [7, 1, 4, 1, 9, 3, 1, 2, 6], @@ -1008,8 +1004,7 @@ function test_Vector_Affine() ), ) @test MOI.output_dimension(f) == 2 - @test f.terms == - MOI.VectorAffineTerm.( + @test f.terms == MOI.VectorAffineTerm.( [1, 1, 2], MOI.ScalarAffineTerm.([2, 4, 3], [x, y, y]), ) @@ -1020,13 +1015,11 @@ function test_Vector_Affine() @test f ≈ g f = MOI.Utilities.modify_function(f, MOI.MultirowChange(y, [(2, 9)])) @test !(f ≈ g) - @test f.terms == - MOI.VectorAffineTerm.( + @test f.terms == MOI.VectorAffineTerm.( [1, 1, 2], MOI.ScalarAffineTerm.([2, 4, 9], [x, y, y]), ) - @test g.terms == - MOI.VectorAffineTerm.( + @test g.terms == MOI.VectorAffineTerm.( [1, 1, 2], MOI.ScalarAffineTerm.([2, 4, 3], [x, y, y]), ) @@ -1055,8 +1048,7 @@ function test_Vector_Quadratic() f, MOI.MultirowChange(y, [(2, 0), (1, 1)]), ) - @test f.affine_terms == - MOI.VectorAffineTerm.( + @test f.affine_terms == MOI.VectorAffineTerm.( [1, 2, 1], MOI.ScalarAffineTerm.([3, 1, 1], [x, x, y]), ) @@ -1065,13 +1057,11 @@ function test_Vector_Quadratic() f, MOI.MultirowChange(x, [(1, 0), (3, 4)]), ) - @test f.affine_terms == - MOI.VectorAffineTerm.( + @test f.affine_terms == MOI.VectorAffineTerm.( [2, 1, 3], MOI.ScalarAffineTerm.([1, 1, 4], [x, y, x]), ) - @test g.affine_terms == - MOI.VectorAffineTerm.( + @test g.affine_terms == MOI.VectorAffineTerm.( [1, 2, 1], MOI.ScalarAffineTerm.([3, 1, 1], [x, x, y]), ) diff --git a/test/Utilities/parser.jl b/test/Utilities/parser.jl index 303b2ddbcc..b2f09cdbba 100644 --- a/test/Utilities/parser.jl +++ b/test/Utilities/parser.jl @@ -97,7 +97,8 @@ end function test__separate_label() @test MOIU._separate_label(:(variables:x)) == (:variables, :x) @test MOIU._separate_label(:(variables:x, y)) == (:variables, :((x, y))) - @test MOIU._separate_label(:(minobjective:x+y)) == (:minobjective, :(x + y)) + @test MOIU._separate_label(:(minobjective:(x+y))) == + (:minobjective, :(x + y)) @test MOIU._separate_label(:(con1:2x <= 1)) == (:con1, :(2x <= 1)) @test MOIU._separate_label(:(con1:[x, y] in S)) == (:con1, :([x, y] in S)) return