[SciPy-Dev] Expose Lapack for Cython

Sturla Molden sturla.molden at gmail.com
Wed Sep 10 12:46:28 EDT 2014


Ian Henriksen <insertinterestingnamehere at gmail.com> wrote:

> Hmm. It's not clear to me exactly how to make a custom Python module with
> additional C level pointers like that that. 

The function pointer instances goes in a lapack.pyx file and the
declarations goes in a corresponding lapack.pxd file. It is similar to what
you would do in C when you have corresponding.c and .h files. The lapack
module must be loaded from SciPy when its __init__.py is executed. This
also initializes the pointers. Just let your lapack.pyx initialize its own
pointers when it is loaded.

Then any other Cython module can "cimport lapack". 

(In reality you don't need to use the f2py objects either, if you link
lapack.pyx with LAPACK when Scipy is built.)


> I'm in the process of looking
> through the C api to see how something like that might be done, but an
> example would be helpful. That would certainly be a good way to take care
> of references though. My end goal is to make these all available in a
> single pxd file. 

It is better to have a .pyx file with a corresponding .pxd file.

> It will be necessary to initialize the struct/module from
> the wrappers in scipy, 

No, this can be avoided if you have corresponding .pyx and .pxd files. You
should only need to "cimport lapack" if you do it right. (Actually it would
be something like "cimport scipy.linalg.lapack.cylapack as lapack".)

See here:

http://docs.cython.org/src/userguide/sharing_declarations.html#sharing-c-functions


Sturla




More information about the SciPy-Dev mailing list