Skip to content

Commit

Permalink
Clean PR wrt #2229.
Browse files Browse the repository at this point in the history
  • Loading branch information
dourouc05 committed Apr 24, 2020
1 parent 1091f19 commit dc77f32
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,37 +156,24 @@ function parse_one_operator_constraint(_error::Function, vectorized::Bool,
return parse_code, _build_call(_error, vectorized, variable, set)
end

function rewrite_call_expression(_error::Function, head::Val{F}, args...) where F
_error("function $F not implemented.")
end

_functionize(v::VariableRef) = convert(AffExpr, v)
_functionize(v::AbstractArray{VariableRef}) = _functionize.(v)
_functionize(x) = x
function parse_one_operator_constraint(_error::Function, vectorized::Bool, sense::Val, lhs, rhs)
parse_code_rhs, build_code_rhs, new_rhs = :(), :(), rhs
if isexpr(rhs, :call) && applicable(rewrite_call_expression, Val(rhs.args[1]), rhs.args[2:end]...)
parse_code_rhs, build_code_rhs, new_rhs = rewrite_call_expression(_error, Val(rhs.args[1]), rhs.args[2:end]...)
end

# Simple comparison - move everything to the LHS.

# TODO: bug in MutableArithmetics? The returned code does not find $new_rhs (ERROR: UndefVarError: #642###976 not defined).
if rhs == new_rhs
if vectorized
func = :($lhs .- $new_rhs)
else
func = :($lhs - $new_rhs)
end
variable, parse_code = _MA.rewrite(func)
#
# Note: We add the +0 to this term to account for the pathological case that
# the `lhs` is a `VariableRef` and the `rhs` is a summation with no terms.
# Without the `+0` term, `aff` would evaluate to a `VariableRef` when we
# really want it to be a `GenericAffExpr`.
if vectorized
func = :($lhs .- $rhs)
else
variable, parse_code = _MA.rewrite(lhs)
parse_code = :($parse_code; $variable = _MA.mutable_operate!(-, convert(AffExpr, $variable), $new_rhs))
func = :($lhs - $rhs)
end

set = sense_to_set(_error, sense)
build_code = _build_call(_error, vectorized, :(_functionize($variable)), set)
return :($parse_code_rhs; $parse_code), :($build_code_rhs; $build_code)
variable, parse_code = _MA.rewrite(func)
return parse_code, _build_call(_error, vectorized, :(_functionize($variable)), set)
end

function parse_constraint(_error::Function, ::Val{:call}, args...)
Expand Down

0 comments on commit dc77f32

Please sign in to comment.