Cleaner implementation of Domain.__or__() (seems slower?)
[linpy.git] / linpy / domains.py
index da0ea97..57c08ba 100644 (file)
@@ -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.
         """
         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:
         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):
 
     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):
     __or__.__doc__ = union.__doc__
 
     def __add__(self, other):
-        return self.union(other)
+        return self | other
     __add__.__doc__ = union.__doc__
 
     def difference(self, other):
     __add__.__doc__ = union.__doc__
 
     def difference(self, other):