Skip to content
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

Update to [email protected] and use return_is_mutable #3885

Merged
merged 1 commit into from
Nov 18, 2024
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DimensionalData = "0.24, 0.25, 0.26.2, 0.27, 0.28, 0.29"
LinearAlgebra = "<0.0.1, 1.6"
MacroTools = "0.5"
MathOptInterface = "1.34.0"
MutableArithmetics = "1.1"
MutableArithmetics = "1.6"
OrderedCollections = "1"
Printf = "<0.0.1, 1.6"
PrecompileTools = "1"
Expand Down
7 changes: 1 addition & 6 deletions src/JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ module JuMP
import LinearAlgebra
import MacroTools
import MathOptInterface as MOI
import MutableArithmetics
import MutableArithmetics as _MA
import OrderedCollections
import OrderedCollections: OrderedDict
import Printf
import SparseArrays

# We can't use import MutableArithmetics as _MA because of a bug in MA.
# Fixed in MutableArithmetics v1.2.3, but would require bumping the compat
# bound so we can keep it as this until necessary.
const _MA = MutableArithmetics

"""
MOIU

Expand Down
17 changes: 7 additions & 10 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,15 @@ expressions.
"""
function _rewrite_expression(expr::Expr)
new_expr = MacroTools.postwalk(_rewrite_to_jump_logic, expr)
new_aff, parse_aff = _MA.rewrite(new_expr; move_factors_into_sums = false)
ret = gensym()
has_copy_if_mutable = Ref(false)
MacroTools.postwalk(parse_aff) do x
if x === MutableArithmetics.copy_if_mutable
has_copy_if_mutable[] = true
end
return x
end
if !has_copy_if_mutable[]
new_aff, parse_aff, is_mutable = _MA.rewrite(
new_expr;
move_factors_into_sums = false,
return_is_mutable = true,
)
if !is_mutable
new_aff = :($_MA.copy_if_mutable($new_aff))
end
ret = gensym()
code = quote
$parse_aff
$ret = $flatten!($new_aff)
Expand Down
Loading