Exposing buffer interface for non-extension types?

Stefan Behnel stefan_ml at behnel.de
Wed Jul 21 04:26:03 EDT 2010


Ken Watford, 21.07.2010 03:04:
 >>> Currently, I can expose the NumPy array interface (using either
 >>> __array_interface__ or __array_struct__) for any class, extension or
 >>> otherwise. But I can't find any reference to python-side interfacing
 >>> for PEP 3118. SWIG makes an extension module for your wrapped code,
 >>> but not extension *types*, so the classes it produces are pure-python
 >>> with methods added in from the extension module.
 >>
 >> Try using Cython instead, it has native support for the buffer protocol.
 >
 > I've used Cython before, and I generally like it. But its purpose is
 > slightly different than SWIG's, and does not particularly meet my
 > current project's needs.
>[...]
> As a part of SWIG-wrapping a larger C++ project, I'm producing some
> wrappings for Blitz++ arrays.

Right, support for C++ templates in Cython isn't as good yet as it could 
be, although there has been some work in that direction. Contributions are 
welcome.

However, note that you can write the tiny bit of plain C++ glue code 
necessary to access the Blitz++ arrays, and then use Cython to wrap that 
and to implement the buffer interface and all the other wrapper code. C++ 
support by itself is pretty good in Cython 0.13. (to be released soon, get 
it from here: http://hg.cython.org/cython-closures )

Stefan




More information about the Python-list mailing list