From: Vivien Maisonneuve Date: Fri, 20 Jun 2014 09:57:42 +0000 (+0200) Subject: Implement isl_basic_set_constraints X-Git-Tag: 1.0~222 X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/commitdiff_plain/efe7abf81717b6bf1f0e6d66352a4c3615538789 Implement isl_basic_set_constraints --- diff --git a/Makefile b/Makefile index edb6c69..cb233ec 100644 --- 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 diff --git a/pypol/__init__.py b/pypol/__init__.py index 7a195ca..451d7f1 100644 --- a/pypol/__init__.py +++ b/pypol/__init__.py @@ -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' ] diff --git a/pypol/_isl.c b/pypol/_isl.c index 974b0c0..7441d46 100644 --- a/pypol/_isl.c +++ b/pypol/_isl.c @@ -1,7 +1,48 @@ +#include + #include -#include +#include +#include + +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} }; diff --git a/pypol/isl.py b/pypol/isl.py index f15cea1..a295e9f 100644 --- a/pypol/isl.py +++ b/pypol/isl.py @@ -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) diff --git a/pypol/linear.py b/pypol/linear.py index e6d442e..c34402a 100644 --- a/pypol/linear.py +++ b/pypol/linear.py @@ -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()) diff --git a/setup.py b/setup.py index caeacb5..b530f28 100755 --- 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']) ] )