X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/966727e8d6a1bcbb27dfb1586daa233b006b4fca..3ff02ec4a397d81d1019080a78198c454861c1e2:/pypol/isl.py diff --git a/pypol/isl.py b/pypol/isl.py index f1e63dc..bbc8d13 100644 --- a/pypol/isl.py +++ b/pypol/isl.py @@ -4,21 +4,22 @@ isl format: basic set: ("{[x, y] : x >= 0 and x < 5 and y >= 0 and y < x+4 }") """ import ctypes, ctypes.util +import functools import math import numbers import operator import re -import functools - from decimal import Decimal from fractions import Fraction from functools import wraps + libisl = ctypes.CDLL(ctypes.util.find_library('isl')) libisl.isl_printer_get_str.restype = ctypes.c_char_p + def _polymorphic_method(func): @functools.wraps(func) def wrapper(self, other): @@ -30,6 +31,7 @@ def _polymorphic_method(func): raise TypeError('operand should be a Value or a Rational') return wrapper + class Context: __slots__ = ('_ic') @@ -40,8 +42,8 @@ class Context: @property def _as_parameter_(self): return self._ic - - #comment out so does not delete itself after being created + + #comment out so does not delete itself after being created #def __del__(self): # libisl.isl_ctx_free(self) @@ -120,19 +122,12 @@ class Value: numerator = libisl.isl_val_read_from_str(context, numerator) denominator = str(frac.denominator).encode() denominator = libisl.isl_val_read_from_str(context, denominator) - self._iv = libisl.isl_val_div(numerator, denominator) + self._iv = libisl.isl_val_div(numerator, denominator) return self - @property def _as_parameter_(self): return self._iv - - def symbols(self): - s = set() - for constraint in self.constraints(): - s.update(constraint.symbols) - yield from sorted(s) def __del__(self): libisl.isl_val_free(self) @@ -147,7 +142,7 @@ class Value: @property def denominator(self): if self._denominator is None: - raise ValueError('not a rational number') + raise ValueError('not a rational number') return self._denominator def __bool__(self): @@ -258,7 +253,7 @@ class Value: return bool(libisl.isl_val_is_infty(self) or libisl.isl_val_is_neginfty(self)) - def is_nan(self): + def is_nan(self): return bool(libisl.isl_val_is_nan(self)) def __str__(self):