.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
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'
]
+#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}
};
from . import _isl
+__all__ = [
+ 'Context',
+ 'BasicSet',
+]
+
+
libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
libisl.isl_printer_get_str.restype = ctypes.c_char_p
def __del__(self):
libisl.isl_basic_set_free(self)
+
+ def constraints(self):
+ return _isl.isl_basic_set_constraints(self._ptr)
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())
author='MINES ParisTech',
packages=['pypol'],
ext_modules = [
- Extension('pypol._isl', sources=['pypol/_isl.c'])
+ Extension('pypol._isl',
+ sources=['pypol/_isl.c'],
+ libraries=['isl'])
]
)