From: Vivien Maisonneuve Date: Tue, 19 Aug 2014 14:30:10 +0000 (+0200) Subject: Cleaner implementation of Domain.__or__() (seems slower?) X-Git-Tag: 1.0~33 X-Git-Url: https://scm.cri.mines-paristech.fr/git/linpy.git/commitdiff_plain/3c9e6c7cd0631426b79a28c9b15f8d40e01cec4c?ds=sidebyside Cleaner implementation of Domain.__or__() (seems slower?) --- diff --git a/linpy/domains.py b/linpy/domains.py index da0ea97..57c08ba 100644 --- a/linpy/domains.py +++ b/linpy/domains.py @@ -340,21 +340,23 @@ 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):