From 3c9e6c7cd0631426b79a28c9b15f8d40e01cec4c Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Tue, 19 Aug 2014 16:30:10 +0200 Subject: [PATCH 1/1] Cleaner implementation of Domain.__or__() (seems slower?) --- linpy/domains.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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): -- 2.20.1