Skip to content

Commit

Permalink
Add errors for Matrix +- AbstractJuMPScalar
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-foster committed Nov 2, 2023
1 parent b11f744 commit bcac431
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 456 in src/operators.jl

View check run for this annotation

Codecov / codecov/patch

src/operators.jl#L455-L456

Added lines #L455 - L456 were not covered by tests
"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

Check warning on line 463 in src/operators.jl

View check run for this annotation

Codecov / codecov/patch

src/operators.jl#L463

Added line #L463 was not covered by tests

function Base.:-(A::Matrix, x::AbstractJuMPScalar)
return error(

Check warning on line 466 in src/operators.jl

View check run for this annotation

Codecov / codecov/patch

src/operators.jl#L465-L466

Added lines #L465 - L466 were not covered by tests
"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

Check warning on line 473 in src/operators.jl

View check run for this annotation

Codecov / codecov/patch

src/operators.jl#L473

Added line #L473 was not covered by tests

0 comments on commit bcac431

Please sign in to comment.