X-Git-Url: https://scm.cri.mines-paristech.fr/git/linpy.git/blobdiff_plain/d1592edb29b12dafe5c0d0698310b98b4915cf26..56e65cb91a4e6759404696f43d44bcebad6b0460:/linpy/domains.py diff --git a/linpy/domains.py b/linpy/domains.py index da0ea97..0da0a49 100644 --- a/linpy/domains.py +++ b/linpy/domains.py @@ -340,35 +340,39 @@ class Domain(GeometricObject): Return the union of two or more domains as a new domain. As an alternative, function Or() can be used. """ - if len(others) == 0: - return self - symbols = self._xsymbols((self,) + others) - islset1 = self._toislset(self.polyhedra, symbols) + result = self for other in others: - islset2 = other._toislset(other.polyhedra, symbols) - islset1 = libisl.isl_set_union(islset1, islset2) - return self._fromislset(islset1, symbols) + result |= other + return result def __or__(self, other): - return self.union(other) + if isinstance(other, Domain): + symbols = self._xsymbols([self, other]) + islset1 = self._toislset(self.polyhedra, symbols) + islset2 = other._toislset(other.polyhedra, symbols) + islset = libisl.isl_set_union(islset1, islset2) + return self._fromislset(islset, symbols) + return NotImplemented __or__.__doc__ = union.__doc__ def __add__(self, other): - return self.union(other) + return self | other __add__.__doc__ = union.__doc__ def difference(self, other): """ Return the difference of two domains as a new domain. """ - symbols = self._xsymbols([self, other]) - islset1 = self._toislset(self.polyhedra, symbols) - islset2 = other._toislset(other.polyhedra, symbols) - islset = libisl.isl_set_subtract(islset1, islset2) - return self._fromislset(islset, symbols) + return self - other def __sub__(self, other): - return self.difference(other) + if isinstance(other, Domain): + symbols = self._xsymbols([self, other]) + islset1 = self._toislset(self.polyhedra, symbols) + islset2 = other._toislset(other.polyhedra, symbols) + islset = libisl.isl_set_subtract(islset1, islset2) + return self._fromislset(islset, symbols) + return NotImplemented __sub__.__doc__ = difference.__doc__ def lexmin(self): @@ -387,7 +391,10 @@ class Domain(GeometricObject): islset = libisl.isl_set_lexmax(islset) return self._fromislset(islset, self.symbols) - _RE_COORDINATE = re.compile(r'\((?P\-?\d+)\)(/(?P\d+))?') + if islhelper.isl_version >= '0.13': + _RE_COORDINATE = re.compile(r'\((?P\-?\d+)\)(/(?P\d+))?') + else: + _RE_COORDINATE = None def vertices(self): """ @@ -405,7 +412,7 @@ class Domain(GeometricObject): for vertex in vertices: expr = libisl.isl_vertex_get_expr(vertex) coordinates = [] - if islhelper.isl_version < '0.13': + if self._RE_COORDINATE is None: constraints = islhelper.isl_basic_set_constraints(expr) for constraint in constraints: constant = libisl.isl_constraint_get_constant_val(constraint) @@ -592,7 +599,7 @@ class Domain(GeometricObject): elif self.dimension == 3: return self._plot_3d(plot=plot, **kwargs) else: - raise ValueError('polyhedron must be 2 or 3-dimensional') + raise ValueError('domain must be 2 or 3-dimensional') def subs(self, symbol, expression=None): """ @@ -730,7 +737,7 @@ class Domain(GeometricObject): @classmethod def fromsympy(cls, expr): """ - Create a domain from a sympy expression. + Create a domain from a SymPy expression. """ import sympy from .polyhedra import Lt, Le, Eq, Ne, Ge, Gt @@ -749,7 +756,7 @@ class Domain(GeometricObject): def tosympy(self): """ - Convert the domain to a sympy expression. + Convert the domain to a SymPy expression. """ import sympy polyhedra = [polyhedron.tosympy() for polyhedron in polyhedra]