Implement isl_basic_set_constraints
authorVivien Maisonneuve <v.maisonneuve@gmail.com>
Fri, 20 Jun 2014 09:57:42 +0000 (11:57 +0200)
committerVivien Maisonneuve <v.maisonneuve@gmail.com>
Fri, 20 Jun 2014 12:11:47 +0000 (14:11 +0200)
Makefile
pypol/__init__.py
pypol/_isl.c
pypol/isl.py
pypol/linear.py
setup.py

index edb6c69..cb233ec 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ test:
 .PHONY: clean
 clean:
        $(RM) build dist MANIFEST venv
-       $(RM) pypol.egg-info pypol/islhelper.*.so pypol/__pycache__
+       $(RM) pypol.egg-info pypol/_isl.*.so pypol/__pycache__
        $(RM) tests/__pycache__
 
 .PHONY: venv
index 7a195ca..451d7f1 100644 (file)
@@ -2,13 +2,13 @@
 A polyhedral library based on ISL.
 """
 
-from .linear import Constant, Symbol, symbols
+from .linear import Polyhedron, Constant, Symbol, symbols
 from .linear import eq, le, lt, ge, gt
 from .linear import Empty, Universe
 
 
 __all__ = [
-    'Constant', 'Symbol', 'symbols',
+    'Polyhedron', 'Constant', 'Symbol', 'symbols',
     'eq', 'le', 'lt', 'ge', 'gt',
     'Empty', 'Universe'
 ]
index 974b0c0..7441d46 100644 (file)
@@ -1,7 +1,48 @@
+#include <stdlib.h>
+
 #include <Python.h>
-#include <isl/space.h>
+#include <isl/constraint.h>
+#include <isl/set.h>
+
+struct _isl_constraint_list {
+    int cursor;
+    PyObject *constraints;
+};
+typedef struct _isl_constraint_list _isl_constraint_list;
+
+int _isl_isl_basic_set_add_constraint_list(__isl_take isl_constraint *c,
+        void *user) {
+    _isl_constraint_list *list;
+
+    list = (_isl_constraint_list *) user;
+    return PyList_SetItem(list->constraints, list->cursor++,
+        PyLong_FromVoidPtr(c));
+}
+
+static PyObject * _isl_isl_basic_set_constraints(PyObject *self,
+        PyObject* args) {
+    long ptr;
+    isl_basic_set *bset;
+    int n;
+    PyObject *constraints;
+    _isl_constraint_list *list;
+
+    if (!PyArg_ParseTuple(args, "l", &ptr))
+        return NULL;
+    bset = (isl_basic_set*) ptr;
+    n = isl_basic_set_n_constraint(bset);
+    constraints = PyList_New(n);
+    list = malloc(sizeof(_isl_constraint_list));
+    list->cursor = 0;
+    list->constraints = constraints;
+    isl_basic_set_foreach_constraint(bset,
+        _isl_isl_basic_set_add_constraint_list, list);
+    free(list);
+    return constraints;
+}
 
 static PyMethodDef _isl_methods[] = {
+    {"isl_basic_set_constraints", _isl_isl_basic_set_constraints, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
index f15cea1..a295e9f 100644 (file)
@@ -3,6 +3,12 @@ import ctypes, ctypes.util
 from . import _isl
 
 
+__all__ = [
+    'Context',
+    'BasicSet',
+]
+
+
 libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
 
 libisl.isl_printer_get_str.restype = ctypes.c_char_p
@@ -51,3 +57,6 @@ class BasicSet(IslObject):
 
     def __del__(self):
         libisl.isl_basic_set_free(self)
+
+    def constraints(self):
+        return _isl.isl_basic_set_constraints(self._ptr)
index e6d442e..c34402a 100644 (file)
@@ -699,7 +699,8 @@ Universe = Polyhedron()
 
 
 if __name__ == '__main__':
-    p1 = Polyhedron('2a + 2b + 1 == 0') # empty
-    print(p1._toisl())
-    p2 = Polyhedron('3x + 2y + 3 == 0') # not empty
-    print(p2._toisl())
+    #p = Polyhedron('2a + 2b + 1 == 0') # empty
+    p = Polyhedron('3x + 2y + 3 == 0, y == 0') # not empty
+    ip = p._toisl()
+    print(ip)
+    print(ip.constraints())
index caeacb5..b530f28 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -8,6 +8,8 @@ setup(
     author='MINES ParisTech',
     packages=['pypol'],
     ext_modules = [
-        Extension('pypol._isl', sources=['pypol/_isl.c'])
+        Extension('pypol._isl',
+            sources=['pypol/_isl.c'],
+            libraries=['isl'])
     ]
 )