32ce305446aaee16354f116b865d09f812707aa5
1 import ctypes
, ctypes
.util
12 libisl
= ctypes
.CDLL(ctypes
.util
.find_library('isl'))
14 libisl
.isl_printer_get_str
.restype
= ctypes
.c_char_p
15 libisl
.isl_dim_set
= _isl
.dim_set
24 def __init__(self
, ptr
):
28 def _as_parameter_(self
):
32 class Context(IslObject
):
35 ptr
= libisl
.isl_ctx_alloc()
38 #comment out so does not delete itself after being created
40 # libisl.isl_ctx_free(self)
42 def __eq__(self
, other
):
43 if not isinstance(other
, Context
):
45 return self
._ptr
== other
._ptr
48 class BasicSet(IslObject
):
51 ls
= libisl
.isl_basic_set_get_local_space(self
)
52 ctx
= libisl
.isl_local_space_get_ctx(ls
)
53 p
= libisl
.isl_printer_to_str(ctx
)
54 p
= libisl
.isl_printer_print_basic_set(p
, self
)
55 string
= libisl
.isl_printer_get_str(p
).decode()
59 libisl
.isl_basic_set_free(self
)
61 def constraints(self
):
62 return _isl
.basic_set_constraints(self
._ptr
)
64 def _fromisl(self
, cls
, symbols
):
65 constraints
= self
.constraints()
72 for constraint
in constraints
:
73 ls
= libisl
.isl_basic_set_get_local_space(self
)
74 ctx
= libisl
.isl_local_space_get_ctx(ls
)
75 p
= libisl
.isl_printer_to_str(ctx
)
76 if libisl
.isl_constraint_is_equality(constraint
): #check if equality
77 constant
= libisl
.isl_constraint_get_constant_val(constraint
)
78 const
= libisl
.isl_printer_print_val(p
, constant
)
79 const
= libisl
.isl_printer_get_str(const
).decode()
81 libisl
.isl_printer_free(p
)
82 for symbol
in symbols
:
83 p
= libisl
.isl_printer_to_str(ctx
)
84 dim
= symbols
.index(symbol
)
85 coefficient
= libisl
.isl_constraint_get_coefficient_val(constraint
, libisl
.isl_dim_set
, dim
)
86 coeff
= libisl
.isl_printer_print_val(p
, coefficient
)
87 coeff
= libisl
.isl_printer_get_str(coeff
).decode()
90 co
.append('{}{}'.format(coeff
, symbols
[dim
]))
92 string
+= '{}+'.format(value
)
93 equalities
.append('{}{}==0'.format(string
, const
))
96 libisl
.isl_printer_free(p
)
97 else: #same for inequality
98 constant
= libisl
.isl_constraint_get_constant_val(constraint
)
99 const
= libisl
.isl_printer_print_val(p
, constant
)
100 const
= libisl
.isl_printer_get_str(const
).decode()
102 libisl
.isl_printer_free(p
)
103 for symbol
in symbols
:
104 p
= libisl
.isl_printer_to_str(ctx
)
105 dim
= symbols
.index(symbol
)
106 coefficient
= libisl
.isl_constraint_get_coefficient_val(constraint
, libisl
.isl_dim_set
, dim
)
107 coeff
= libisl
.isl_printer_print_val(p
, coefficient
)
108 coeff
= libisl
.isl_printer_get_str(coeff
).decode()
111 co
.append('{}{}'.format(coeff
, symbols
[dim
]))
113 string
+= '{} + '.format(value
)
114 inequalities
.append('{}{} <= 0'.format(string
, const
))
117 libisl
.isl_printer_free(p
)
119 for equations
in equalities
:
120 eq_string
+= ' {}'.format(equations
)
121 eq_strings
= eq_string
.split()
124 for equations
in inequalities
:
125 in_string
+= ', {}'.format(equations
)
127 if eq_string
and in_string
:
128 final
= '{}, {}'.format(eq_string
, in_string
)
129 elif eq_string
!= '':
130 final
= '{}'.format(eq_strings
)
131 elif in_string
!= '' :
132 final
= '{}'.format(in_string
)
135 return ('{}({!r})'.format(cls
.__name
__,final
))