[Numpy-discussion] Numpy and C++ integration...

Matthieu Brucher matthieu.brucher@gmail....
Mon Feb 4 10:39:42 CST 2008


2008/2/4, Lou Pecora <lou_boog2000@yahoo.com>:
>
> Dear Mr. Fulco ,
>
> This may not be exactly what you want to do, but I
> would recommend using the C API and then calling your
> C++ programs from there (where interface functions to
> the C++ code is compiled in the extern "C" {,  }
> block.  I will be doing this soon with my own project.
> Why?  Because the C interface is doable and, I think,
> simple enough that it is better to take the Python to
> C++ in two steps.  Anyway, worth a look.  So here are
> two links that show how to use the C API:
>
> http://www.scipy.org/Cookbook/C_Extensions  - A short
> intro, this also has documentation links
>
>
> http://www.scipy.org/Cookbook/C_Extensions/NumPy_arrays?highlight=%28%28----%28-%2A%29%28%5Cr%29%3F%5Cn%29%28.%2A%29CategoryCookbook%5Cb%29
>   - This is an article I wrote last year for the
> SciPy.org site and I go into a lot of detail with a
> lot of examples on how you pass and handle Numpy
> arrays.  I think it is (mostly) right and works well
> for me.
>
> One warning (which I also talk about in my tutorial)
> is to make sure your NumPy arrays are "Continguous",
> i.e. the array components are in order in one memory
> block.  That makes things easier on the C/C++ side.


Whatever solution you choose (Boost.Python, ...), you will have to use the
Numpy C API at least a little bit. So Travis' book is a good start. As Gaël
told you, you can use ctypes if you wrap manually every method with a C
function and recreate the class in Python.
This can be avoided, but you'll have to use more powerful tools. I would
advice SWIG (see my blog for some examples with C++ and SWIG).

Matthieu
-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080204/61cc2934/attachment.html 


More information about the Numpy-discussion mailing list