Is it possible to write to/from python converts with Cython?

227 views Asked by At

Is it possible to write to-python and from-python converters using Cython like it is possible for boost.python?

Edit (on comment request, with more details on why we'd like this):

We currently have code that is written in C++ that is bound to Python via boost.python. In this C++ code, we deal with Blitz::Array<>'s. In our current abstraction scheme, code in Python uses NumPy's ndarrays, while code in C++ uses Blitz::Arrays<>. We have written a bridge that can convert from numpy.ndarray's to Blitz::Array<>'s and vice-versa, in a quite transparent manner. This bridge can also avoid copying in some circumstances, what is bonus.

Issues with this approach:

  1. Portability: compiling for different versions of Python requires that Boost.Python is compiled for each version of Python;

  2. Documentability: including Python docstrings in C++ code is not very nice. It has discouraged our developers to implement nice looking documentation. It often looks patching and incomplete;

  3. Build speed: compiling boost.python templates can be quite slow. We do this in parallel using CMake to speed-up, but then we would like to create a stock Python egg with our project. As you are probably aware setuptools/distutils and CMake don't mix very well so we have some sort of patchy way to do things in this domain.

So, given the prospect of Cython, I thought we would give it a try and find a less hacky way to solve all these issues. We already have a code-base that relies on numpy.ndarray and I'd like to leverage from that as much as possible, with minimal writing and maximum reuse of our C++ code base. Therefore, my question.

0

There are 0 answers