Skip to content

Commit c75e265

Browse files
blegatodow
authored andcommitted
Use objectid
1 parent b680d05 commit c75e265

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/JuMP.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ mutable struct GenericModel{T<:Real} <: AbstractModel
163163
enable_macro_timing::Bool
164164
macro_times::Dict{Tuple{LineNumberNode,String},Float64}
165165
# We use `Any` as key because we haven't defined `GenericNonlinearExpr` yet
166-
subexpressions::Dict{Any,MOI.ScalarNonlinearFunction}
166+
subexpressions::Dict{UInt64,MOI.ScalarNonlinearFunction}
167167
end
168168

169169
value_type(::Type{GenericModel{T}}) where {T} = T
@@ -278,7 +278,7 @@ function direct_generic_model(
278278
Dict{Any,MOI.ConstraintIndex}(),
279279
false,
280280
Dict{Tuple{LineNumberNode,String},Float64}(),
281-
Dict{Any,MOI.ScalarNonlinearFunction}(),
281+
Dict{UInt64,MOI.ScalarNonlinearFunction}(),
282282
)
283283
end
284284

src/nlp_expr.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,9 @@ function moi_function(
588588
model::JuMP.GenericModel,
589589
) where {V}
590590
cache = model.subexpressions
591-
if haskey(cache, f)
592-
return cache[f]
591+
key = objectid(f)
592+
if haskey(cache, key)
593+
return cache[key]
593594
end
594595
ret = MOI.ScalarNonlinearFunction(f.head, similar(f.args))
595596
stack = Tuple{MOI.ScalarNonlinearFunction,Int,GenericNonlinearExpr{V}}[]
@@ -604,8 +605,9 @@ function moi_function(
604605
end
605606
while !isempty(stack)
606607
parent, i, arg = pop!(stack)
607-
if haskey(cache, arg)
608-
parent.args[i] = cache[arg]
608+
arg_key = objectid(arg)
609+
if haskey(cache, arg_key)
610+
parent.args[i] = cache[arg_key]
609611
continue
610612
end
611613
child = MOI.ScalarNonlinearFunction(arg.head, similar(arg.args))
@@ -617,9 +619,9 @@ function moi_function(
617619
child.args[j] = moi_function(arg.args[j])
618620
end
619621
end
620-
cache[arg] = child
622+
cache[arg_key] = child
621623
end
622-
cache[f] = ret
624+
cache[key] = ret
623625
return ret
624626
end
625627

0 commit comments

Comments
 (0)