@@ -36,11 +36,11 @@ Note: Discarding the result of `destructive_add!` suggests an improper usage.
3636"""
3737function destructive_add! end
3838
39- destructive_add! (ex:: Constant , c:: Constant , x:: Constant ) = ex + c* x
39+ destructive_add! (ex:: _Constant , c:: _Constant , x:: _Constant ) = ex + c* x
4040
41- destructive_add! (ex:: Constant , c:: Constant , x:: AbstractVariableRef ) = GenericAffExpr (_float (ex), x => _float (c))
41+ destructive_add! (ex:: _Constant , c:: _Constant , x:: AbstractVariableRef ) = GenericAffExpr (_float (ex), x => _float (c))
4242
43- function destructive_add! (ex:: Constant , c:: Constant , x:: T ) where T<: GenericAffExpr
43+ function destructive_add! (ex:: _Constant , c:: _Constant , x:: T ) where T<: GenericAffExpr
4444 # It's only safe to mutate the first argument.
4545 if iszero (c)
4646 convert (T, ex)
@@ -51,7 +51,7 @@ function destructive_add!(ex::Constant, c::Constant, x::T) where T<:GenericAffEx
5151 end
5252end
5353
54- function destructive_add! (ex:: Constant , c:: Constant , x:: T ) where T<: GenericQuadExpr
54+ function destructive_add! (ex:: _Constant , c:: _Constant , x:: T ) where T<: GenericQuadExpr
5555 # It's only safe to mutate the first argument.
5656 if iszero (c)
5757 convert (T, ex)
@@ -62,25 +62,25 @@ function destructive_add!(ex::Constant, c::Constant, x::T) where T<:GenericQuadE
6262 end
6363end
6464
65- function destructive_add! (ex:: Constant , c:: AbstractVariableRef , x:: AbstractVariableRef )
65+ function destructive_add! (ex:: _Constant , c:: AbstractVariableRef , x:: AbstractVariableRef )
6666 result = c* x
6767 result. aff. constant += ex
6868 result
6969end
7070
71- function destructive_add! (ex:: Constant , c:: T , x:: T ) where T<: GenericAffExpr
71+ function destructive_add! (ex:: _Constant , c:: T , x:: T ) where T<: GenericAffExpr
7272 q = c* x
7373 q. aff. constant += ex
7474 q
7575end
7676
77- function destructive_add! (ex:: Constant , c:: GenericAffExpr{C,V} , x:: V ) where {C,V}
77+ function destructive_add! (ex:: _Constant , c:: GenericAffExpr{C,V} , x:: V ) where {C,V}
7878 q = c* x
7979 q. aff. constant += ex
8080 q
8181end
8282
83- function destructive_add! (ex:: Constant , c:: T , x:: Constant ) where T<: GenericQuadExpr
83+ function destructive_add! (ex:: _Constant , c:: T , x:: _Constant ) where T<: GenericQuadExpr
8484 if iszero (x)
8585 convert (T, ex)
8686 else
@@ -90,24 +90,24 @@ function destructive_add!(ex::Constant, c::T, x::Constant) where T<:GenericQuadE
9090 end
9191end
9292
93- function destructive_add! (ex:: AbstractVariableRef , c:: Constant , x:: AbstractVariableRef )
93+ function destructive_add! (ex:: AbstractVariableRef , c:: _Constant , x:: AbstractVariableRef )
9494 return GenericAffExpr (0.0 , ex => 1.0 , x => _float (c))
9595end
96- function destructive_add! (ex:: AbstractVariableRef , c:: Constant , x:: Constant )
96+ function destructive_add! (ex:: AbstractVariableRef , c:: _Constant , x:: _Constant )
9797 return GenericAffExpr (_float (c * x), ex => 1.0 )
9898end
9999
100- function destructive_add! (aff:: GenericAffExpr , c:: Constant , x:: Constant )
100+ function destructive_add! (aff:: GenericAffExpr , c:: _Constant , x:: _Constant )
101101 aff. constant += c* x
102102 aff
103103end
104104
105- function destructive_add! (aff:: GenericAffExpr{C,V} , c:: Constant , x:: V ) where {C,V}
105+ function destructive_add! (aff:: GenericAffExpr{C,V} , c:: _Constant , x:: V ) where {C,V}
106106 add_to_expression! (aff, convert (C, c), x)
107107 aff
108108end
109109
110- function destructive_add! (aff:: GenericAffExpr{C,V} ,c:: Constant ,x:: GenericAffExpr{C,V} ) where {C,V}
110+ function destructive_add! (aff:: GenericAffExpr{C,V} ,c:: _Constant ,x:: GenericAffExpr{C,V} ) where {C,V}
111111 if ! iszero (c)
112112 sizehint! (aff, length (linear_terms (aff)) + length (linear_terms (x)))
113113 for (coef, var) in linear_terms (x)
@@ -119,9 +119,9 @@ function destructive_add!(aff::GenericAffExpr{C,V},c::Constant,x::GenericAffExpr
119119end
120120
121121# help w/ ambiguity
122- destructive_add! (aff:: GenericAffExpr{C,V} , c:: Constant , x:: Constant ) where {C,V<: Constant } = aff + c* x
122+ destructive_add! (aff:: GenericAffExpr{C,V} , c:: _Constant , x:: _Constant ) where {C,V<: _Constant } = aff + c* x
123123
124- function destructive_add! (aff:: GenericAffExpr{C,V} , c:: V , x:: Constant ) where {C,V}
124+ function destructive_add! (aff:: GenericAffExpr{C,V} , c:: V , x:: _Constant ) where {C,V}
125125 if ! iszero (x)
126126 add_to_expression! (aff, convert (C, x), c)
127127 end
@@ -146,11 +146,11 @@ function destructive_add!(aff::GenericAffExpr, c::AbstractVariableRef, x::Generi
146146 quad
147147end
148148
149- function destructive_add! (aff:: GenericAffExpr{C,V} ,c:: GenericAffExpr{C,V} ,x:: Constant ) where {C,V}
149+ function destructive_add! (aff:: GenericAffExpr{C,V} ,c:: GenericAffExpr{C,V} ,x:: _Constant ) where {C,V}
150150 destructive_add! (aff, x, c)
151151end
152152
153- function destructive_add! (aff:: GenericAffExpr{C,V} , c:: GenericQuadExpr{C,V} , x:: Constant ) where {C,V}
153+ function destructive_add! (aff:: GenericAffExpr{C,V} , c:: GenericQuadExpr{C,V} , x:: _Constant ) where {C,V}
154154 if iszero (x)
155155 GenericQuadExpr {C,V} (aff)
156156 else
@@ -160,7 +160,7 @@ function destructive_add!(aff::GenericAffExpr{C,V}, c::GenericQuadExpr{C,V}, x::
160160 end
161161end
162162
163- function destructive_add! (aff:: GenericAffExpr{C,V} , c:: Constant , x:: GenericQuadExpr{C,V} ) where {C,V}
163+ function destructive_add! (aff:: GenericAffExpr{C,V} , c:: _Constant , x:: GenericQuadExpr{C,V} ) where {C,V}
164164 if iszero (c)
165165 GenericQuadExpr {C,V} (aff)
166166 else
@@ -175,14 +175,14 @@ function destructive_add!(ex::GenericAffExpr{C,V}, c::GenericAffExpr{C,V}, x::Ge
175175 destructive_add! (q, one (C), c* x)
176176end
177177
178- function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: Constant ,x:: V ) where {C,V}
178+ function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: _Constant ,x:: V ) where {C,V}
179179 if ! iszero (c)
180180 add_to_expression! (quad. aff, convert (C, c), x)
181181 end
182182 quad
183183end
184184
185- function destructive_add! (quad:: GenericQuadExpr ,c:: Constant ,x:: Constant )
185+ function destructive_add! (quad:: GenericQuadExpr ,c:: _Constant ,x:: _Constant )
186186 quad. aff. constant += c* x
187187 quad
188188end
@@ -192,12 +192,12 @@ function destructive_add!(quad::GenericQuadExpr{C,V},x::V,y::V) where {C,V}
192192 quad
193193end
194194
195- function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: Constant ,x:: GenericAffExpr{C,V} ) where {C,V}
195+ function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: _Constant ,x:: GenericAffExpr{C,V} ) where {C,V}
196196 quad. aff = destructive_add! (quad. aff, c, x)
197197 quad
198198end
199199
200- function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: GenericAffExpr{C,V} ,x:: Constant ) where {C,V}
200+ function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: GenericAffExpr{C,V} ,x:: _Constant ) where {C,V}
201201 quad. aff = destructive_add! (quad. aff,c,x)
202202 quad
203203end
@@ -222,7 +222,7 @@ function destructive_add!(quad::GenericQuadExpr{C,V},c::V,x::GenericAffExpr{C,V}
222222 quad
223223end
224224
225- function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: GenericQuadExpr{C,V} ,x:: Constant ) where {C,V}
225+ function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: GenericQuadExpr{C,V} ,x:: _Constant ) where {C,V}
226226 if ! iszero (x)
227227 for (coef, var1, var2) in quad_terms (c)
228228 add_to_expression! (quad, x* coef, var1, var2)
@@ -232,7 +232,7 @@ function destructive_add!(quad::GenericQuadExpr{C,V},c::GenericQuadExpr{C,V},x::
232232 quad
233233end
234234
235- function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: Constant ,x:: GenericQuadExpr{C,V} ) where {C,V}
235+ function destructive_add! (quad:: GenericQuadExpr{C,V} ,c:: _Constant ,x:: GenericQuadExpr{C,V} ) where {C,V}
236236 if ! iszero (c)
237237 for (coef, var1, var2) in quad_terms (x)
238238 add_to_expression! (quad, c* coef, var1, var2)
@@ -253,20 +253,20 @@ _nl_expr_err() = error("""Cannot use nonlinear expression or parameter in @const
253253 Use @NLconstraint or @NLobjective instead.""" )
254254# Following three definitions avoid ambiguity warnings
255255destructive_add! (expr:: GenericQuadExpr{C,V} , c:: GenericAffExpr{C,V} , x:: V ) where {C,V<: _NLExpr } = _nl_expr_err ()
256- destructive_add! (expr:: GenericQuadExpr{C,V} , c:: Constant , x:: V ) where {C,V<: _NLExpr } = _nl_expr_err ()
256+ destructive_add! (expr:: GenericQuadExpr{C,V} , c:: _Constant , x:: V ) where {C,V<: _NLExpr } = _nl_expr_err ()
257257destructive_add! (expr:: GenericQuadExpr{C,V} , c:: V , x:: GenericAffExpr{C,V} ) where {C,V<: _NLExpr } = _nl_expr_err ()
258- for T1 in (GenericAffExpr,GenericQuadExpr), T2 in (Constant ,VariableRef,GenericAffExpr,GenericQuadExpr)
258+ for T1 in (GenericAffExpr,GenericQuadExpr), T2 in (_Constant ,VariableRef,GenericAffExpr,GenericQuadExpr)
259259 @eval destructive_add! (:: $T1 , :: $T2 , :: _NLExpr ) = _nl_expr_err ()
260260 @eval destructive_add! (:: $T1 , :: _NLExpr , :: $T2 ) = _nl_expr_err ()
261261end
262262
263263function destructive_add! (ex:: AbstractArray{T} , c:: AbstractArray , x:: AbstractArray ) where {T<: GenericAffExpr }
264264 add_to_expression! .(ex, c* x)
265265end
266- function destructive_add! (ex:: AbstractArray{T} , c:: AbstractArray , x:: Constant ) where {T<: GenericAffExpr }
266+ function destructive_add! (ex:: AbstractArray{T} , c:: AbstractArray , x:: _Constant ) where {T<: GenericAffExpr }
267267 add_to_expression! .(ex, c* x)
268268end
269- function destructive_add! (ex:: AbstractArray{T} , c:: Constant , x:: AbstractArray ) where {T<: GenericAffExpr }
269+ function destructive_add! (ex:: AbstractArray{T} , c:: _Constant , x:: AbstractArray ) where {T<: GenericAffExpr }
270270 add_to_expression! .(ex, c* x)
271271end
272272function destructive_add! (ex:: AbstractArray{T} , c:: Number , x:: Number ) where {T<: GenericAffExpr }
@@ -285,18 +285,18 @@ end
285285function destructive_add! (c:: Number , x:: UniformScaling , ex:: AbstractArray{<:AbstractJuMPScalar} )
286286 add_to_expression! .(x * ex, c)
287287end
288- function destructive_add! (c:: UniformScaling , x:: Constant , ex:: AbstractArray{<:AbstractJuMPScalar} )
288+ function destructive_add! (c:: UniformScaling , x:: _Constant , ex:: AbstractArray{<:AbstractJuMPScalar} )
289289 return c + x * ex
290290end
291291
292292function destructive_add! (ex:: AbstractArray{<:GenericAffExpr} ,
293293 c:: AbstractArray{<:GenericQuadExpr} ,
294- x:: Constant )
294+ x:: _Constant )
295295 result = c* x
296296 add_to_expression! .(result, ex)
297297 return result
298298end
299- function destructive_add! (ex:: AbstractArray{<:GenericAffExpr} , c:: Constant ,
299+ function destructive_add! (ex:: AbstractArray{<:GenericAffExpr} , c:: _Constant ,
300300 x:: AbstractArray{<:GenericQuadExpr} )
301301 result = c* x
302302 add_to_expression! .(result, ex)
@@ -320,7 +320,7 @@ _destructive_add_with_reorder!(ex::Val{false}, args...) = (*)(args...)
320320
321321
322322@generated function _destructive_add_with_reorder! (ex, x, y)
323- if x <: Union{AbstractVariableRef,GenericAffExpr} && y <: Constant
323+ if x <: Union{AbstractVariableRef,GenericAffExpr} && y <: _Constant
324324 :(destructive_add! (ex, y, x))
325325 else
326326 :(destructive_add! (ex, x, y))
331331 n = length (args)
332332 @assert n ≥ 3
333333 varidx = findall (t -> (t <: AbstractVariableRef || t <: GenericAffExpr ), collect (args))
334- allscalar = all (t -> (t <: Constant ), args[setdiff (1 : n, varidx)])
334+ allscalar = all (t -> (t <: _Constant ), args[setdiff (1 : n, varidx)])
335335 idx = (allscalar && length (varidx) == 1 ) ? varidx[1 ] : n
336336 coef = Expr (:call , :* , [:(args[$ i]) for i in setdiff (1 : n,idx)]. .. )
337337 :(destructive_add! (ex, $ coef, args[$ idx]))
0 commit comments