X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/efe7abf81717b6bf1f0e6d66352a4c3615538789..66e41ccd173874b3309e4c24be64c7b6b2ac6298:/pypol/isl.py?ds=inline diff --git a/pypol/isl.py b/pypol/isl.py index a295e9f..32ce305 100644 --- a/pypol/isl.py +++ b/pypol/isl.py @@ -12,7 +12,7 @@ __all__ = [ libisl = ctypes.CDLL(ctypes.util.find_library('isl')) libisl.isl_printer_get_str.restype = ctypes.c_char_p -libisl.isl_dim_set = _isl.isl_dim_set +libisl.isl_dim_set = _isl.dim_set class IslObject: @@ -59,4 +59,78 @@ class BasicSet(IslObject): libisl.isl_basic_set_free(self) def constraints(self): - return _isl.isl_basic_set_constraints(self._ptr) + return _isl.basic_set_constraints(self._ptr) + + def _fromisl(self, cls, symbols): + constraints = self.constraints() + equalities = [] + inequalities = [] + co = [] + eq_string = "" + in_string = "" + string = "" + for constraint in constraints: + ls = libisl.isl_basic_set_get_local_space(self) + ctx = libisl.isl_local_space_get_ctx(ls) + p = libisl.isl_printer_to_str(ctx) + if libisl.isl_constraint_is_equality(constraint): #check if equality + constant = libisl.isl_constraint_get_constant_val(constraint) + const = libisl.isl_printer_print_val(p, constant) + const = libisl.isl_printer_get_str(const).decode() + const = int(const) + libisl.isl_printer_free(p) + for symbol in symbols: + p = libisl.isl_printer_to_str(ctx) + dim = symbols.index(symbol) + coefficient = libisl.isl_constraint_get_coefficient_val(constraint, libisl.isl_dim_set, dim) + coeff = libisl.isl_printer_print_val(p, coefficient) + coeff = libisl.isl_printer_get_str(coeff).decode() + coeff = int(coeff) + if coeff!=0: + co.append('{}{}'.format(coeff, symbols[dim])) + for value in co: + string += '{}+'.format(value) + equalities.append('{}{}==0'.format(string, const)) + co = [] + string = '' + libisl.isl_printer_free(p) + else: #same for inequality + constant = libisl.isl_constraint_get_constant_val(constraint) + const = libisl.isl_printer_print_val(p, constant) + const = libisl.isl_printer_get_str(const).decode() + const = int(const) + libisl.isl_printer_free(p) + for symbol in symbols: + p = libisl.isl_printer_to_str(ctx) + dim = symbols.index(symbol) + coefficient = libisl.isl_constraint_get_coefficient_val(constraint, libisl.isl_dim_set, dim) + coeff = libisl.isl_printer_print_val(p, coefficient) + coeff = libisl.isl_printer_get_str(coeff).decode() + coeff = int(coeff) + if coeff!=0: + co.append('{}{}'.format(coeff, symbols[dim])) + for value in co: + string += '{} + '.format(value) + inequalities.append('{}{} <= 0'.format(string, const)) + co = [] + string = "" + libisl.isl_printer_free(p) + + for equations in equalities: + eq_string += ' {}'.format(equations) + eq_strings = eq_string.split() + print(eq_strings) + + for equations in inequalities: + in_string += ', {}'.format(equations) + print(in_string) + if eq_string and in_string: + final = '{}, {}'.format(eq_string, in_string) + elif eq_string != '': + final = '{}'.format(eq_strings) + elif in_string != '' : + final = '{}'.format(in_string) + + + return ('{}({!r})'.format(cls.__name__,final)) +