X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/600e193f0f6ba62014cb5ac3d804504cb064b0ac..66e41ccd173874b3309e4c24be64c7b6b2ac6298:/pypol/isl.py?ds=sidebyside diff --git a/pypol/isl.py b/pypol/isl.py index 0b9a485..32ce305 100644 --- a/pypol/isl.py +++ b/pypol/isl.py @@ -60,3 +60,77 @@ class BasicSet(IslObject): def constraints(self): 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)) +