diff --git a/src/operators.jl b/src/operators.jl index 5310234ddc0..2478a89fb36 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -451,3 +451,23 @@ function LinearAlgebra.issymmetric(x::Matrix{T}) where {T<:_JuMPTypes} end return true end + +function Base.:+(A::Matrix, x::AbstractJuMPScalar) + return error( + "Addition between a Matrix and a JuMP variable is not supported: instead of A + x, " * + "prefer A .+ x for element-wise addition, or if you are modifying the diagonal entries of the matrix " * + "do A + x * LinearAlgebra.I(n), where n is the diagonal length." + ) +end + +Base.:+(x::AbstractJuMPScalar, A::Matrix) = A + x + +function Base.:-(A::Matrix, x::AbstractJuMPScalar) + return error( + "Subtraction between a Matrix and a JuMP variable is not supported: instead of A - x, " * + "prefer A .- x for element-wise subtraction, or if you are modifying the diagonal entries of the matrix " * + "do A - x * LinearAlgebra.I(n), where n is the diagonal length." + ) +end + +Base.:-(x::AbstractJuMPScalar, A::Matrix) = A - x \ No newline at end of file