Skip to content

Commit 6479f39

Browse files
committed
Constant -> _Constant
1 parent 9a2e00e commit 6479f39

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

src/operators.jl

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,58 @@
99
#############################################################################
1010

1111
const _JuMPTypes = Union{AbstractJuMPScalar, NonlinearExpression}
12-
const Constant = Union{Number, UniformScaling}
12+
const _Constant = Union{Number, UniformScaling}
1313
_float(x::Number) = convert(Float64, x)
1414
_float(J::UniformScaling) = _float(J.λ)
1515

1616
# Overloads
1717
#
1818
# Different objects that must all interact:
19-
# 1. Constant
19+
# 1. _Constant
2020
# 2. AbstractVariableRef
2121
# 4. GenericAffExpr
2222
# 5. GenericQuadExpr
2323

24-
# Constant
25-
# Constant--Constant obviously already taken care of!
26-
# Constant--VariableRef
27-
Base.:+(lhs::Constant, rhs::AbstractVariableRef) = GenericAffExpr(_float(lhs), rhs => 1.0)
28-
Base.:-(lhs::Constant, rhs::AbstractVariableRef) = GenericAffExpr(_float(lhs), rhs => -1.0)
29-
Base.:*(lhs::Constant, rhs::AbstractVariableRef) = GenericAffExpr(0.0, rhs => _float(lhs))
30-
# Constant--GenericAffExpr
31-
function Base.:+(lhs::Constant, rhs::GenericAffExpr)
24+
# _Constant
25+
# _Constant--_Constant obviously already taken care of!
26+
# _Constant--VariableRef
27+
Base.:+(lhs::_Constant, rhs::AbstractVariableRef) = GenericAffExpr(_float(lhs), rhs => 1.0)
28+
Base.:-(lhs::_Constant, rhs::AbstractVariableRef) = GenericAffExpr(_float(lhs), rhs => -1.0)
29+
Base.:*(lhs::_Constant, rhs::AbstractVariableRef) = GenericAffExpr(0.0, rhs => _float(lhs))
30+
# _Constant--GenericAffExpr
31+
function Base.:+(lhs::_Constant, rhs::GenericAffExpr)
3232
result = copy(rhs)
3333
result.constant += lhs
3434
return result
3535
end
36-
function Base.:-(lhs::Constant, rhs::GenericAffExpr)
36+
function Base.:-(lhs::_Constant, rhs::GenericAffExpr)
3737
result = -rhs
3838
result.constant += lhs
3939
return result
4040
end
41-
function Base.:*(lhs::Constant, rhs::GenericAffExpr)
41+
function Base.:*(lhs::_Constant, rhs::GenericAffExpr)
4242
f = _float(lhs)
4343
return map_coefficients(c -> f * c, rhs)
4444
end
45-
# Constant--QuadExpr
46-
Base.:+(lhs::Constant, rhs::GenericQuadExpr) = GenericQuadExpr(lhs+rhs.aff, copy(rhs.terms))
47-
function Base.:-(lhs::Constant, rhs::GenericQuadExpr)
45+
# _Constant--QuadExpr
46+
Base.:+(lhs::_Constant, rhs::GenericQuadExpr) = GenericQuadExpr(lhs+rhs.aff, copy(rhs.terms))
47+
function Base.:-(lhs::_Constant, rhs::GenericQuadExpr)
4848
result = -rhs
4949
result.aff.constant += lhs
5050
return result
5151
end
52-
Base.:*(lhs::Constant, rhs::GenericQuadExpr) = map_coefficients(c -> lhs * c, rhs)
52+
Base.:*(lhs::_Constant, rhs::GenericQuadExpr) = map_coefficients(c -> lhs * c, rhs)
5353

5454
# AbstractVariableRef (or, AbstractJuMPScalar)
5555
# TODO: What is the role of AbstractJuMPScalar??
5656
Base.:+(lhs::AbstractJuMPScalar) = lhs
5757
Base.:-(lhs::AbstractVariableRef) = GenericAffExpr(0.0, lhs => -1.0)
5858
Base.:*(lhs::AbstractJuMPScalar) = lhs # make this more generic so extensions don't have to define unary multiplication for our macros
59-
# AbstractVariableRef--Constant
60-
Base.:+(lhs::AbstractVariableRef, rhs::Constant) = (+)( rhs,lhs)
61-
Base.:-(lhs::AbstractVariableRef, rhs::Constant) = (+)(-rhs,lhs)
62-
Base.:*(lhs::AbstractVariableRef, rhs::Constant) = (*)(rhs,lhs)
63-
Base.:/(lhs::AbstractVariableRef, rhs::Constant) = (*)(1.0/rhs,lhs)
59+
# AbstractVariableRef--_Constant
60+
Base.:+(lhs::AbstractVariableRef, rhs::_Constant) = (+)( rhs,lhs)
61+
Base.:-(lhs::AbstractVariableRef, rhs::_Constant) = (+)(-rhs,lhs)
62+
Base.:*(lhs::AbstractVariableRef, rhs::_Constant) = (*)(rhs,lhs)
63+
Base.:/(lhs::AbstractVariableRef, rhs::_Constant) = (*)(1.0/rhs,lhs)
6464
# AbstractVariableRef--AbstractVariableRef
6565
Base.:+(lhs::V, rhs::V) where {V <: AbstractVariableRef} = GenericAffExpr(0.0, lhs => 1.0, rhs => 1.0)
6666
Base.:-(lhs::V, rhs::V) where {V <: AbstractVariableRef} = GenericAffExpr(0.0, lhs => 1.0, rhs => -1.0)
@@ -117,11 +117,11 @@ end
117117
# GenericAffExpr
118118
Base.:+(lhs::GenericAffExpr) = lhs
119119
Base.:-(lhs::GenericAffExpr) = map_coefficients(-, lhs)
120-
# GenericAffExpr--Constant
121-
Base.:+(lhs::GenericAffExpr, rhs::Constant) = (+)(rhs,lhs)
122-
Base.:-(lhs::GenericAffExpr, rhs::Constant) = (+)(-rhs,lhs)
123-
Base.:*(lhs::GenericAffExpr, rhs::Constant) = (*)(rhs,lhs)
124-
Base.:/(lhs::GenericAffExpr, rhs::Constant) = map_coefficients(c -> c/rhs, lhs)
120+
# GenericAffExpr--_Constant
121+
Base.:+(lhs::GenericAffExpr, rhs::_Constant) = (+)(rhs,lhs)
122+
Base.:-(lhs::GenericAffExpr, rhs::_Constant) = (+)(-rhs,lhs)
123+
Base.:*(lhs::GenericAffExpr, rhs::_Constant) = (*)(rhs,lhs)
124+
Base.:/(lhs::GenericAffExpr, rhs::_Constant) = map_coefficients(c -> c/rhs, lhs)
125125
function Base.:^(lhs::Union{AbstractVariableRef, GenericAffExpr}, rhs::Integer)
126126
if rhs == 2
127127
return lhs*lhs
@@ -133,7 +133,7 @@ function Base.:^(lhs::Union{AbstractVariableRef, GenericAffExpr}, rhs::Integer)
133133
error("Only exponents of 0, 1, or 2 are currently supported. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.")
134134
end
135135
end
136-
Base.:^(lhs::Union{AbstractVariableRef, GenericAffExpr}, rhs::Constant) = error("Only exponents of 0, 1, or 2 are currently supported. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.")
136+
Base.:^(lhs::Union{AbstractVariableRef, GenericAffExpr}, rhs::_Constant) = error("Only exponents of 0, 1, or 2 are currently supported. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.")
137137
# GenericAffExpr--AbstractVariableRef
138138
function Base.:+(lhs::GenericAffExpr{C, V}, rhs::V) where {C, V <: AbstractVariableRef}
139139
return add_to_expression!(copy(lhs), one(C), rhs)
@@ -193,11 +193,11 @@ end
193193
# GenericQuadExpr
194194
Base.:+(lhs::GenericQuadExpr) = lhs
195195
Base.:-(lhs::GenericQuadExpr) = map_coefficients(-, lhs)
196-
# GenericQuadExpr--Constant
197-
Base.:+(lhs::GenericQuadExpr, rhs::Constant) = (+)(+rhs,lhs)
198-
Base.:-(lhs::GenericQuadExpr, rhs::Constant) = (+)(-rhs,lhs)
199-
Base.:*(lhs::GenericQuadExpr, rhs::Constant) = (*)(rhs,lhs)
200-
Base.:/(lhs::GenericQuadExpr, rhs::Constant) = (*)(inv(rhs),lhs)
196+
# GenericQuadExpr--_Constant
197+
Base.:+(lhs::GenericQuadExpr, rhs::_Constant) = (+)(+rhs,lhs)
198+
Base.:-(lhs::GenericQuadExpr, rhs::_Constant) = (+)(-rhs,lhs)
199+
Base.:*(lhs::GenericQuadExpr, rhs::_Constant) = (*)(rhs,lhs)
200+
Base.:/(lhs::GenericQuadExpr, rhs::_Constant) = (*)(inv(rhs),lhs)
201201
# GenericQuadExpr--AbstractVariableRef
202202
Base.:+(q::GenericQuadExpr, v::AbstractVariableRef) = GenericQuadExpr(q.aff+v, copy(q.terms))
203203
Base.:-(q::GenericQuadExpr, v::AbstractVariableRef) = GenericQuadExpr(q.aff-v, copy(q.terms))
@@ -277,8 +277,8 @@ end
277277
# for scalars, so instead of defining them one-by-one, we will
278278
# fallback to the multiplication operator
279279
LinearAlgebra.dot(lhs::_JuMPTypes, rhs::_JuMPTypes) = lhs*rhs
280-
LinearAlgebra.dot(lhs::_JuMPTypes, rhs::Constant) = lhs*rhs
281-
LinearAlgebra.dot(lhs::Constant, rhs::_JuMPTypes) = lhs*rhs
280+
LinearAlgebra.dot(lhs::_JuMPTypes, rhs::_Constant) = lhs*rhs
281+
LinearAlgebra.dot(lhs::_Constant, rhs::_JuMPTypes) = lhs*rhs
282282

283283
LinearAlgebra.dot(lhs::AbstractVector{T}, rhs::AbstractVector{S}) where {T <: _JuMPTypes, S <: _JuMPTypes} = _dot(lhs,rhs)
284284
LinearAlgebra.dot(lhs::AbstractVector{T}, rhs::AbstractVector{S}) where {T <: _JuMPTypes, S} = _dot(lhs,rhs)
@@ -366,7 +366,7 @@ end
366366
# `_A_mul_B!(ret, A, B)` adds the result of `A*B` into the buffer `ret`. We roll our own
367367
# matmul here (instead of using Julia's generic fallbacks) because doing so allows us to
368368
# accumulate the expressions for the inner loops in-place. Additionally, Julia's generic
369-
# fallbacks can be finnicky when your array elements aren't `<:Constant`.
369+
# fallbacks can be finnicky when your array elements aren't `<:_Constant`.
370370
#
371371
# No bounds/size checks are performed; it is expected that the caller has done this, has
372372
# ensured that the eltype of `ret` is appropriate, and has zeroed the elements of `ret` (if
@@ -547,7 +547,7 @@ Base.:*(A::Transpose{<:Any, <:SparseMatrixCSC}, B::Matrix{<:_JuMPTypes}) = _At_m
547547
Base.:*(A::Transpose{<:_JuMPTypes, <:SparseMatrixCSC}, B::Matrix{<:_JuMPTypes}) = _At_mul_B(parent(A), B)
548548

549549
# Base doesn't define efficient fallbacks for sparse array arithmetic involving
550-
# non-`<:Constant` scalar elements, so we define some of these for `<:JuMPType` scalar
550+
# non-`<:_Constant` scalar elements, so we define some of these for `<:JuMPType` scalar
551551
# elements here.
552552

553553
function Base.:*(A::Number, B::SparseMatrixCSC{<:_JuMPTypes})
@@ -611,6 +611,6 @@ Base.:*(lhs::GenericQuadExpr, rhs::GenericQuadExpr) =
611611
Base.:*(::S, ::T) where {T <: GenericQuadExpr,
612612
S <: Union{AbstractVariableRef, GenericAffExpr, GenericQuadExpr}} =
613613
error( "*(::$S,::$T) is not defined. $op_hint")
614-
Base.:/(::S, ::T) where {S <: Union{Constant, AbstractVariableRef, GenericAffExpr, GenericQuadExpr},
614+
Base.:/(::S, ::T) where {S <: Union{_Constant, AbstractVariableRef, GenericAffExpr, GenericQuadExpr},
615615
T <: Union{AbstractVariableRef, GenericAffExpr, GenericQuadExpr}} =
616616
error( "/(::$S,::$T) is not defined. $op_hint")

src/parse_expr.jl

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ Note: Discarding the result of `destructive_add!` suggests an improper usage.
3636
"""
3737
function 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
5252
end
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
6363
end
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
6969
end
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
7575
end
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
8181
end
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
9191
end
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))
9595
end
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)
9898
end
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
103103
end
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
108108
end
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
119119
end
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
147147
end
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)
151151
end
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
161161
end
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)
176176
end
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
183183
end
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
188188
end
@@ -192,12 +192,12 @@ function destructive_add!(quad::GenericQuadExpr{C,V},x::V,y::V) where {C,V}
192192
quad
193193
end
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
198198
end
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
203203
end
@@ -222,7 +222,7 @@ function destructive_add!(quad::GenericQuadExpr{C,V},c::V,x::GenericAffExpr{C,V}
222222
quad
223223
end
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
233233
end
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
255255
destructive_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()
257257
destructive_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()
261261
end
262262

263263
function destructive_add!(ex::AbstractArray{T}, c::AbstractArray, x::AbstractArray) where {T<:GenericAffExpr}
264264
add_to_expression!.(ex, c*x)
265265
end
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)
268268
end
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)
271271
end
272272
function destructive_add!(ex::AbstractArray{T}, c::Number, x::Number) where {T<:GenericAffExpr}
@@ -285,18 +285,18 @@ end
285285
function destructive_add!(c::Number, x::UniformScaling, ex::AbstractArray{<:AbstractJuMPScalar})
286286
add_to_expression!.(x * ex, c)
287287
end
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
290290
end
291291

292292
function 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
298298
end
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))
@@ -331,7 +331,7 @@ end
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

Comments
 (0)