Isl update with no errors
authorDanielle Bolan <n02702451@hawkmail.newpaltz.edu>
Mon, 2 Jun 2014 09:22:50 +0000 (11:22 +0200)
committerDanielle Bolan <n02702451@hawkmail.newpaltz.edu>
Mon, 2 Jun 2014 09:22:50 +0000 (11:22 +0200)
pypol/isl.py

index 758fb79..74cc5d3 100644 (file)
@@ -4,6 +4,7 @@ import math
 import numbers
 import operator
 import re
 import numbers
 import operator
 import re
+import functools
 
 from decimal import Decimal
 from fractions import Fraction
 
 from decimal import Decimal
 from fractions import Fraction
@@ -14,6 +15,16 @@ libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
 
 libisl.isl_printer_get_str.restype = ctypes.c_char_p
 
 
 libisl.isl_printer_get_str.restype = ctypes.c_char_p
 
+def _polymorphic_method(func):
+    @functools.wraps(func)
+    def wrapper(self, other):
+        if isinstance(other, Value):
+            return func(self, other)
+        if isinstance(other, numbers.Rational):
+            other = Value(self.context, other)
+            return func(self, other)
+        raise TypeError('operand should be a Value or a Rational')
+    return wrapper
 
 class Context:
 
 
 class Context:
 
@@ -130,34 +141,23 @@ class Value:
     def __bool__(self):
         return not bool(libisl.isl_val_is_zero(self))
 
     def __bool__(self):
         return not bool(libisl.isl_val_is_zero(self))
 
-    def _polymorphic(func):
-        @wraps(func)
-        def wrapper(self, other):
-            if isinstance(other, Value):
-                return func(self, other)
-            if isinstance(other, numbers.Rational):
-                other = Value(self.context, other)
-                return func(self, other)
-            raise TypeError('operand should be a Value or a Rational')
-        return wrapper
-
-    @_polymorphic
+    @_polymorphic_method
     def __lt__(self, other):
         return bool(libisl.isl_val_lt(self, other))
 
     def __lt__(self, other):
         return bool(libisl.isl_val_lt(self, other))
 
-    @_polymorphic
+    @_polymorphic_method
     def __le__(self, other):
         return bool(libisl.isl_val_le(self, other))
 
     def __le__(self, other):
         return bool(libisl.isl_val_le(self, other))
 
-    @_polymorphic
+    @_polymorphic_method
     def __gt__(self, other):
         return bool(libisl.isl_val_gt(self, other))
 
     def __gt__(self, other):
         return bool(libisl.isl_val_gt(self, other))
 
-    @_polymorphic
+    @_polymorphic_method
     def __ge__(self, other):
         return bool(libisl.isl_val_ge(self, other))
 
     def __ge__(self, other):
         return bool(libisl.isl_val_ge(self, other))
 
-    @_polymorphic
+    @_polymorphic_method
     def __eq__(self, other):
         return bool(libisl.isl_val_eq(self, other))
 
     def __eq__(self, other):
         return bool(libisl.isl_val_eq(self, other))
 
@@ -192,7 +192,7 @@ class Value:
         val = libisl.isl_val_trunc(val)
         return self.__class__(self.context, self._ptr(val))
 
         val = libisl.isl_val_trunc(val)
         return self.__class__(self.context, self._ptr(val))
 
-    @_polymorphic
+    @_polymorphic_method
     def __add__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)
     def __add__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)
@@ -201,7 +201,7 @@ class Value:
 
     __radd__ = __add__
 
 
     __radd__ = __add__
 
-    @_polymorphic
+    @_polymorphic_method
     def __sub__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)
     def __sub__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)
@@ -210,7 +210,7 @@ class Value:
 
     __rsub__ = __sub__
 
 
     __rsub__ = __sub__
 
-    @_polymorphic
+    @_polymorphic_method
     def __mul__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)
     def __mul__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)
@@ -219,7 +219,7 @@ class Value:
 
     __rmul__ = __mul__
 
 
     __rmul__ = __mul__
 
-    @_polymorphic
+    @_polymorphic_method
     def __truediv__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)
     def __truediv__(self, other):
         val1 = libisl.isl_val_copy(self)
         val2 = libisl.isl_val_copy(other)