[Numpy-discussion] NumPtr vs NumPy.i to access C

Brian Granger ellisonbg.net@gmail....
Sat May 17 21:35:58 CDT 2008


Jose,

As you can see, people have different preferences for wrapping C/C++
code.  I should also mention that one of the easiest methods if numpy
arrays are involved is ctypes.  numpy arrays already have more-or-less
built-in support for talking to ctypes.  Details are available here:

http://www.scipy.org/Cookbook/Ctypes

The good news is that there are _many_ good options.  I also know that
the numpy.i file for handling numpy arrays in SWIG is of high quality
and has decent documentation.

Brian


On Sat, May 17, 2008 at 4:55 PM, Jose Martin <maitai02@excite.com> wrote:
>
> Hi, I'd like to access a C function from python, and the function takes input/output arrays. I'd probably use SWIG to do the interface to the C code. I found 2 options:
> -NumPtr module, to access Numeric arrays as pointers
> http://www.penzilla.net/tutorials/python/numptr/
> - numpy.i, a SWIG interface file for NumPy that defines typemaps
> http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/doc/swig/doc/numpy_swig.html
>
> I'm not sure if there is significant differences between the 2 options (besides using either NumPy or Numeric). Does numpy.i interface file use pointers to access NumPy arrays? or does it make a copy of the array to pass it to/from the C function?
>
> I'm new to programming and I'd like to make sure of this. I need to use in C very large arrays frequently, so I want to avoid making copies of it, because speed will be an important factor.
>
> Thanks in advance!
>
>
>
> _______________________________________________
> Join Excite! - http://www.excite.com
> The most personalized portal on the Web!
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the Numpy-discussion mailing list