Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors for Matrix ± AbstractJuMPScalar #3557

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
end
return true
end

function Base.:+(A::Matrix, x::AbstractJuMPScalar)
jd-foster marked this conversation as resolved.
Show resolved Hide resolved
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, " *
jd-foster marked this conversation as resolved.
Show resolved Hide resolved
"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
jd-foster marked this conversation as resolved.
Show resolved Hide resolved

function Base.:-(A::Matrix, x::AbstractJuMPScalar)
jd-foster marked this conversation as resolved.
Show resolved Hide resolved
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."
jd-foster marked this conversation as resolved.
Show resolved Hide resolved
)
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
Loading