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