Skip to content

Commit

Permalink
Change MutableArithmetics.rewrite to move_factors_into_sums=false
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jun 8, 2023
1 parent 85a68de commit 5fdad52
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
MathOptInterface = "1.14"
MutableArithmetics = "1"
MutableArithmetics = "1.1"
OrderedCollections = "1"
SnoopPrecompile = "1"
julia = "1.6"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/manual/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ julia> @variable(model, y)
y
julia> ex = @expression(model, x^2 + 2 * x * y + y^2 + x + y - 1)
x² + 2 y*x + y² + x + y - 1
x² + 2 x*y + y² + x + y - 1
```

### Operator overloading
Expand Down
2 changes: 1 addition & 1 deletion src/complement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ function parse_constraint_call(
F,
x,
)
f, parse_code = _MA.rewrite(F)
f, parse_code = _MA.rewrite(F; move_factors_into_sums = false)
return parse_code, :(_build_complements_constraint($errorf, $f, $(esc(x))))
end
14 changes: 7 additions & 7 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ function parse_constraint_head(
"`$ub >= ... >= $lb`.",
)
end
new_aff, parse_aff = _MA.rewrite(aff)
new_lb, parse_lb = _MA.rewrite(lb)
new_ub, parse_ub = _MA.rewrite(ub)
new_aff, parse_aff = _MA.rewrite(aff; move_factors_into_sums = false)
new_lb, parse_lb = _MA.rewrite(lb; move_factors_into_sums = false)
new_ub, parse_ub = _MA.rewrite(ub; move_factors_into_sums = false)
parse_code = quote
$parse_aff
$parse_lb
Expand Down Expand Up @@ -583,7 +583,7 @@ function parse_constraint_call(
func,
set,
)
f, parse_code = _MA.rewrite(func)
f, parse_code = _MA.rewrite(func; move_factors_into_sums = false)
build_call = if vectorized
:(build_constraint.($_error, _desparsify($f), Ref($(esc(set)))))
else
Expand Down Expand Up @@ -617,7 +617,7 @@ function parse_constraint_call(
rhs,
)
func = vectorized ? :($lhs .- $rhs) : :($lhs - $rhs)
f, parse_code = _MA.rewrite(func)
f, parse_code = _MA.rewrite(func; move_factors_into_sums = false)
set = operator_to_set(_error, operator)
# `_functionize` deals with the pathological case where the `lhs` is a
# `VariableRef` and the `rhs` is a summation with no terms.
Expand Down Expand Up @@ -1496,7 +1496,7 @@ macro objective(model, args...)
end
sense, x = args
sense_expr = _moi_sense(_error, sense)
newaff, parsecode = _MA.rewrite(x)
newaff, parsecode = _MA.rewrite(x; move_factors_into_sums = false)
code = quote
$parsecode
# Don't leak a `_MA.Zero` if the objective expression is an empty
Expand Down Expand Up @@ -1585,7 +1585,7 @@ macro expression(args...)
"different name for the index.",
)
end
code = _MA.rewrite_and_return(x)
code = _MA.rewrite_and_return(x; move_factors_into_sums = false)
code = quote
# Don't leak a `_MA.Zero` if the expression is an empty summation, or
# other structure that returns `_MA.Zero()`.
Expand Down
2 changes: 1 addition & 1 deletion test/test_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ end
function test_Error_on_unexpected_comparison()
m = Model()
@variable(m, x)
@test_macro_throws ErrorException @expression(m, x <= 1)
@test_throws ErrorException @expression(m, x <= 1)
return
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function test_printing_expressions()
"x_{1}\\times y_{2,2} + x_{2}\\times y_{2,2} + z$ijulia_sq + 3 x_{1} + 3 x_{2} - 1",
)

ex = @expression(mod, -z * x[1] - x[1] * z + x[1] * x[2] + 0 * z^2)
ex = @expression(mod, -z * x[1] - z * x[1] + x[1] * x[2] + 0 * z^2)
io_test(MIME("text/plain"), ex, "-2 z*x[1] + x[1]*x[2]")
io_test(MIME("text/latex"), ex, "-2 z\\times x_{1} + x_{1}\\times x_{2}")

Expand Down

0 comments on commit 5fdad52

Please sign in to comment.