From: Vivien Maisonneuve Date: Wed, 20 Aug 2014 12:15:16 +0000 (+0200) Subject: Rename expr variables into expression for consistency X-Git-Tag: 1.0~3 X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/commitdiff_plain/4162c0430092e0ba2b8d8d62b5de24cdd71abe3b?ds=sidebyside;hp=2b13a146860ac116ce0388d8f7551044c09c55f7 Rename expr variables into expression for consistency --- diff --git a/linpy/domains.py b/linpy/domains.py index 432e275..45f55a5 100644 --- a/linpy/domains.py +++ b/linpy/domains.py @@ -411,10 +411,10 @@ class Domain(GeometricObject): 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) @@ -426,7 +426,7 @@ class Domain(GeometricObject): 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')) @@ -730,7 +730,7 @@ class Domain(GeometricObject): return 'Or({})'.format(', '.join(strings)) @classmethod - def fromsympy(cls, expr): + def fromsympy(cls, expression): """ Create a domain from a SymPy expression. """ @@ -742,12 +742,12 @@ class Domain(GeometricObject): 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): """ diff --git a/linpy/linexprs.py b/linpy/linexprs.py index ee6e39e..3c00f22 100644 --- a/linpy/linexprs.py +++ b/linpy/linexprs.py @@ -348,10 +348,10 @@ class LinExpr: # 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 = '' @@ -385,7 +385,7 @@ class LinExpr: 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. @@ -393,7 +393,7 @@ class LinExpr: 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 @@ -405,23 +405,23 @@ class LinExpr: 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): diff --git a/linpy/polyhedra.py b/linpy/polyhedra.py index c05432a..1ccbe9c 100644 --- a/linpy/polyhedra.py +++ b/linpy/polyhedra.py @@ -318,10 +318,10 @@ class Polyhedron(Domain): 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): @@ -380,75 +380,75 @@ Universe = UniverseType() 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)