Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 11, 2024
1 parent 5036c98 commit c4b82f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,9 @@ end
function Base.:+(a::GenericAffExpr, q::GenericQuadExpr)
return GenericQuadExpr(a + q.aff, copy(q.terms))
end
function Base.:-(a::GenericAffExpr, q::GenericQuadExpr)
result = -q
# This makes an unnecessary copy of aff, but it's important for a to appear
# first.
result.aff = a + result.aff
function Base.:-(a::GenericAffExpr{S}, q::GenericQuadExpr{T}) where {S,T}
result = -_copy_convert_coef(_MA.promote_operation(-, S, T), q)
add_to_expression!(result.aff, a)
return result
end

Expand Down
12 changes: 12 additions & 0 deletions test/test_operator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,18 @@ function test_base_complex()
return
end

function test_aff_minus_quad()
model = Model()
@variable(model, x)
a, b = 1.0 * x, (2 + 3im) * x^2
@test a - b == -(b - a)
@test b - a == -(a - b)
a, b = (1.0 + 2im) * x, 3 * x^2 + 4 * x
@test a - b == -(b - a)
@test b - a == -(a - b)
return
end

function test_hermitian_and_symmetric()
model = Model()
@variable(model, A[1:2, 1:2], Symmetric)
Expand Down

0 comments on commit c4b82f3

Please sign in to comment.