X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/ddd4ffae2055577597ec46bf195bd401aaa9c625..bec8e9379d875b91dd49058aeae0075bda66d6d8:/pypol/isl.py?ds=inline diff --git a/pypol/isl.py b/pypol/isl.py index 74cc5d3..f1e63dc 100644 --- a/pypol/isl.py +++ b/pypol/isl.py @@ -1,3 +1,7 @@ +""" +note: for islpy +isl format: basic set: ("{[x, y] : x >= 0 and x < 5 and y >= 0 and y < x+4 }") +""" import ctypes, ctypes.util import math @@ -6,11 +10,11 @@ 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 @@ -36,9 +40,10 @@ class Context: @property def _as_parameter_(self): return self._ic - - def __del__(self): - libisl.isl_ctx_free(self) + + #comment out so does not delete itself after being created + #def __del__(self): + # libisl.isl_ctx_free(self) def __eq__(self, other): if not isinstance(other, Context): @@ -115,12 +120,19 @@ 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) @@ -135,7 +147,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): @@ -246,7 +258,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):