5a20514fd858d9f410ba8139ca3052c8dfe4aa9e
[linpy.git] / pypol / isl.py
1 """
2 note: for islpy
3 isl format: basic set: ("{[x, y] : x >= 0 and x < 5 and y >= 0 and y < x+4 }")
4 """
5
6 import ctypes, ctypes.util
7 import functools
8 import math
9 import numbers
10 import operator
11 import re
12
13 from . import _isl
14
15
16 libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
17
18 libisl.isl_printer_get_str.restype = ctypes.c_char_p
19 libisl.isl_dim_set = _isl.isl_dim_set
20
21
22 class IslObject:
23
24 __slots__ = ('_ptr')
25
26 def __init__(self, ptr):
27 self._ptr = ptr
28
29 @property
30 def _as_parameter_(self):
31 return self._ptr
32
33
34 class Context(IslObject):
35
36 def __init__(self):
37 self._ptr = libisl.isl_ctx_alloc()
38
39 #comment out so does not delete itself after being created
40 #def __del__(self):
41 # libisl.isl_ctx_free(self)
42
43 def __eq__(self, other):
44 if not isinstance(other, Context):
45 return False
46 return self._ptr == other._ptr
47
48
49 class BasicSet(IslObject):
50
51 def __str__(self):
52 ls = libisl.isl_basic_set_get_local_space(self)
53 ctx = libisl.isl_local_space_get_ctx(ls)
54 p = libisl.isl_printer_to_str(ctx)
55 p = libisl.isl_printer_print_basic_set(p, self)
56 string = libisl.isl_printer_get_str(p)
57 string = str(string.decode())
58 return string