Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
left_check = isAffine(expr.left, include_div, include_modulo)
right_check = isAffine(expr.right, include_div, include_modulo)
if (left_check and right_check):
if (expr.op in ['+','-']):
return True
elif(expr.op in ['*']):
if(not (expr.left.has(constructs.Variable) or \
expr.left.has(constructs.Parameter)) or \
not (expr.right.has(constructs.Variable) or \
expr.right.has(constructs.Parameter))):
return True
else:
return False
elif(include_div and expr.op in ['/']):
if (not (expr.right.has(constructs.Variable)) and \
not (expr.right.has(constructs.Parameter))):
return True
else:
return False
elif(include_modulo and expr.op in ['%']):
if (not (expr.right.has(constructs.Variable)) and \
not (expr.right.has(constructs.Parameter))):
return isAffine(expr.left, include_div, False)
else:
return False
else:
return False
else:
return False
elif (isinstance(expr, AbstractUnaryOpNode)):
return isAffine(expr.child, include_div, include_modulo)
elif (isinstance(expr, constructs.Condition)):
return (expr.typ is Int) or (include_div and (expr.typ is Rational))
elif (isinstance(expr, constructs.Variable)):
return True
elif (isinstance(expr, constructs.Reference)):
return False
elif (isinstance(expr, AbstractBinaryOpNode)):
left_check = isAffine(expr.left, include_div, include_modulo)
right_check = isAffine(expr.right, include_div, include_modulo)
if (left_check and right_check):
if (expr.op in ['+','-']):
return True
elif(expr.op in ['*']):
if(not (expr.left.has(constructs.Variable) or \
expr.left.has(constructs.Parameter)) or \
not (expr.right.has(constructs.Variable) or \
expr.right.has(constructs.Parameter))):
return True
else:
return False
elif(include_div and expr.op in ['/']):
if (not (expr.right.has(constructs.Variable)) and \
not (expr.right.has(constructs.Parameter))):
return True
else:
return False
elif(include_modulo and expr.op in ['%']):
if (not (expr.right.has(constructs.Variable)) and \
not (expr.right.has(constructs.Parameter))):
return isAffine(expr.left, include_div, False)
else:
return False
else: