Fix 3d plots in examples
[linpy.git] / linpy / islhelper.py
1 # Copyright 2014 MINES ParisTech
2 #
3 # This file is part of LinPy.
4 #
5 # LinPy is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # LinPy is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with LinPy. If not, see <http://www.gnu.org/licenses/>.
17
18 import ctypes
19 import ctypes.util
20 import re
21
22 from . import _islhelper
23 from ._islhelper import (isl_basic_set_constraints, isl_set_basic_sets,
24 isl_set_points, isl_vertices_vertices)
25
26
27 __all__ = [
28 'isl_basic_set_constraints',
29 'isl_basic_set_to_str',
30 'isl_multi_aff_to_str',
31 'isl_set_basic_sets',
32 'isl_set_points',
33 'isl_set_to_str',
34 'isl_val_to_int',
35 'isl_version',
36 'isl_vertices_vertices',
37 'libisl',
38 'mainctx',
39 ]
40
41
42 libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
43 libisl.isl_dim_set = _islhelper.dim_set
44
45 libisl.isl_version.restype = ctypes.c_char_p
46 isl_version = libisl.isl_version().decode().strip()
47 isl_version = re.sub(r'^isl-', '', isl_version)
48
49
50 mainctx = libisl.isl_ctx_alloc()
51
52
53 libisl.isl_printer_get_str.restype = ctypes.c_char_p
54
55
56 def isl_val_to_int(islval):
57 islpr = libisl.isl_printer_to_str(mainctx)
58 islpr = libisl.isl_printer_print_val(islpr, islval)
59 string = libisl.isl_printer_get_str(islpr).decode()
60 return int(string)
61
62
63 def isl_basic_set_to_str(islbset):
64 islpr = libisl.isl_printer_to_str(mainctx)
65 islpr = libisl.isl_printer_print_basic_set(islpr, islbset)
66 string = libisl.isl_printer_get_str(islpr).decode()
67 return string
68
69
70 def isl_set_to_str(islset):
71 islpr = libisl.isl_printer_to_str(mainctx)
72 islpr = libisl.isl_printer_print_set(islpr, islset)
73 string = libisl.isl_printer_get_str(islpr).decode()
74 return string
75
76
77 def isl_multi_aff_to_str(islmaff):
78 islpr = libisl.isl_printer_to_str(mainctx)
79 islpr = libisl.isl_printer_print_multi_aff(islpr, islmaff)
80 string = libisl.isl_printer_get_str(islpr).decode()
81 return string