vertices = islhelper.isl_vertices_vertices(vertices)
points = []
for vertex in vertices:
- expr = libisl.isl_vertex_get_expr(vertex)
+ expression = libisl.isl_vertex_get_expr(vertex)
coordinates = []
if self._RE_COORDINATE is None:
- constraints = islhelper.isl_basic_set_constraints(expr)
+ constraints = islhelper.isl_basic_set_constraints(expression)
for constraint in constraints:
constant = libisl.isl_constraint_get_constant_val(constraint)
constant = islhelper.isl_val_to_int(constant)
coordinate = -Fraction(constant, coefficient)
coordinates.append((symbol, coordinate))
else:
- string = islhelper.isl_multi_aff_to_str(expr)
+ string = islhelper.isl_multi_aff_to_str(expression)
matches = self._RE_COORDINATE.finditer(string)
for symbol, match in zip(self.symbols, matches):
numerator = int(match.group('num'))
return 'Or({})'.format(', '.join(strings))
@classmethod
- def fromsympy(cls, expr):
+ def fromsympy(cls, expression):
"""
Create a domain from a SymPy expression.
"""
sympy.Eq: Eq, sympy.Ne: Ne,
sympy.Ge: Ge, sympy.Gt: Gt,
}
- if expr.func in funcmap:
- args = [Domain.fromsympy(arg) for arg in expr.args]
- return funcmap[expr.func](*args)
- elif isinstance(expr, sympy.Expr):
- return LinExpr.fromsympy(expr)
- raise ValueError('non-domain expression: {!r}'.format(expr))
+ if expression.func in funcmap:
+ args = [Domain.fromsympy(arg) for arg in expression.args]
+ return funcmap[expression.func](*args)
+ elif isinstance(expression, sympy.Expr):
+ return LinExpr.fromsympy(expression)
+ raise ValueError('non-domain expression: {!r}'.format(expression))
def tosympy(self):
"""
# Add implicit multiplication operators, e.g. '5x' -> '5*x'.
string = LinExpr._RE_NUM_VAR.sub(r'\1*\2', string)
tree = ast.parse(string, 'eval')
- expr = cls._fromast(tree)
- if not isinstance(expr, cls):
+ expression = cls._fromast(tree)
+ if not isinstance(expression, cls):
raise SyntaxError('invalid syntax')
- return expr
+ return expression
def __repr__(self):
string = ''
return '({})'.format(string)
@classmethod
- def fromsympy(cls, expr):
+ def fromsympy(cls, expression):
"""
Create a linear expression from a SymPy expression. Raise TypeError is
the sympy expression is not linear.
import sympy
coefficients = []
constant = 0
- for symbol, coefficient in expr.as_coefficients_dict().items():
+ for symbol, coefficient in expression.as_coefficients_dict().items():
coefficient = Fraction(coefficient.p, coefficient.q)
if symbol == sympy.S.One:
constant = coefficient
symbol = Symbol(symbol.name)
coefficients.append((symbol, coefficient))
else:
- raise TypeError('non-linear expression: {!r}'.format(expr))
- expr = LinExpr(coefficients, constant)
- if not isinstance(expr, cls):
+ raise TypeError('non-linear expression: {!r}'.format(expression))
+ expression = LinExpr(coefficients, constant)
+ if not isinstance(expression, cls):
raise TypeError('cannot convert to a {} instance'.format(cls.__name__))
- return expr
+ return expression
def tosympy(self):
"""
Convert the linear expression to a SymPy expression.
"""
import sympy
- expr = 0
+ expression = 0
for symbol, coefficient in self.coefficients():
term = coefficient * sympy.Symbol(symbol.name)
- expr += term
- expr += self.constant
- return expr
+ expression += term
+ expression += self.constant
+ return expression
class Symbol(LinExpr):
return 'And({})'.format(', '.join(strings))
@classmethod
- def fromsympy(cls, expr):
- domain = Domain.fromsympy(expr)
+ def fromsympy(cls, expression):
+ domain = Domain.fromsympy(expression)
if not isinstance(domain, Polyhedron):
- raise ValueError('non-polyhedral expression: {!r}'.format(expr))
+ raise ValueError('non-polyhedral expression: {!r}'.format(expression))
return domain
def tosympy(self):
def _pseudoconstructor(func):
@functools.wraps(func)
- def wrapper(expr1, expr2, *exprs):
- exprs = (expr1, expr2) + exprs
- for expr in exprs:
- if not isinstance(expr, LinExpr):
- if isinstance(expr, numbers.Rational):
- expr = Rational(expr)
+ def wrapper(expression1, expression2, *expressions):
+ expressions = (expression1, expression2) + expressions
+ for expression in expressions:
+ if not isinstance(expression, LinExpr):
+ if isinstance(expression, numbers.Rational):
+ expression = Rational(expression)
else:
raise TypeError('arguments must be rational numbers '
'or linear expressions')
- return func(*exprs)
+ return func(*expressions)
return wrapper
@_pseudoconstructor
-def Lt(*exprs):
+def Lt(*expressions):
"""
Create the polyhedron with constraints expr1 < expr2 < expr3 ...
"""
inequalities = []
- for left, right in zip(exprs, exprs[1:]):
+ for left, right in zip(expressions, expressions[1:]):
inequalities.append(right - left - 1)
return Polyhedron([], inequalities)
@_pseudoconstructor
-def Le(*exprs):
+def Le(*expressions):
"""
Create the polyhedron with constraints expr1 <= expr2 <= expr3 ...
"""
inequalities = []
- for left, right in zip(exprs, exprs[1:]):
+ for left, right in zip(expressions, expressions[1:]):
inequalities.append(right - left)
return Polyhedron([], inequalities)
@_pseudoconstructor
-def Eq(*exprs):
+def Eq(*expressions):
"""
Create the polyhedron with constraints expr1 == expr2 == expr3 ...
"""
equalities = []
- for left, right in zip(exprs, exprs[1:]):
+ for left, right in zip(expressions, expressions[1:]):
equalities.append(left - right)
return Polyhedron(equalities, [])
@_pseudoconstructor
-def Ne(*exprs):
+def Ne(*expressions):
"""
Create the domain such that expr1 != expr2 != expr3 ... The result is a
Domain object, not a Polyhedron.
"""
domain = Universe
- for left, right in zip(exprs, exprs[1:]):
+ for left, right in zip(expressions, expressions[1:]):
domain &= ~Eq(left, right)
return domain
@_pseudoconstructor
-def Ge(*exprs):
+def Ge(*expressions):
"""
Create the polyhedron with constraints expr1 >= expr2 >= expr3 ...
"""
inequalities = []
- for left, right in zip(exprs, exprs[1:]):
+ for left, right in zip(expressions, expressions[1:]):
inequalities.append(left - right)
return Polyhedron([], inequalities)
@_pseudoconstructor
-def Gt(*exprs):
+def Gt(*expressions):
"""
Create the polyhedron with constraints expr1 > expr2 > expr3 ...
"""
inequalities = []
- for left, right in zip(exprs, exprs[1:]):
+ for left, right in zip(expressions, expressions[1:]):
inequalities.append(left - right - 1)
return Polyhedron([], inequalities)