[Numpy-discussion] A C++ library and the new array interface: the best approach?

Travis Oliphant oliphant.travis at ieee.org
Mon Jul 3 18:06:42 CDT 2006


Fernando Perez wrote:
> Hi all,
>
> but my lack of familiarity with all the details of new type creation got me a 
> bit lost.  I'm sure the information I need is all there, but right now I don't 
> really see the forest with all the leaves in my face.  I've also read the 
> various recent threads on ctypes, as well was the one initiated by Joris:
>
> http://article.gmane.org/gmane.comp.python.numeric.general/6296
>
>
> So I'd like to know if SWIG is really the best way out in this particular case 
> (and any advice on taking advantage of the array interface via SWIG would be 
> appreciated), or if ctypes or pyrex could be used here.  I'm quite happy using 
> pyrex in other contexts, but I know it doesn't directly support C++.  However, 
> since I have access to all the code, perhaps a pure C layer could be used to 
> bridge the C++/pyrex gap.  Or given the recent praise for ctypes, perhaps that 
> can be an option?
>   

I don't have a lot of time to respond right now.  But here are some 
thoughts.

I'm not sure I'd use SWIG at this point. 

I'd probably either

a) use ctypes to call the C++ library (if it is compiled as a *shared* 
library) although to be honest I'm not sure if calling a C++ causes any 
grief. 

b) byte-the bullet and use Boost python (which other's who have 
integrated C++ code with Python seem to really like).  I've never 
wrapped my mind around Boost python, though, so I'm not much help there.

c) write a custom Tensor class that either inherits from the ndarray or 
is a mix-in class with the ndarray as a component.

If it were me, I'd probably be doing a combination of a and c.

I've just finished the chapter in my book that covers and compares f2py, 
weave, pyrex and ctypes integration.   I've been waiting on finishing 
this chapter before sending updates.  You should get the update by the 
end of the week.


Perhaps more later.


-Travis



> Any advice will be greatly appreciated.
>
> Best,
>
> f
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>   





More information about the Numpy-discussion mailing list