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

Bill Spotz wfspotz@sandia....
Sat May 17 22:27:09 CDT 2008

Just to make sure the original question gets answered, yes, numpy.i  
avoids copies as much as possible.

A special case is when your C code provides you with a view of its  
internal data and does not require any memory to be allocated by the  
(python) user.  This can be dangerous, but if it is your use case, be  
sure to use the ARGOUTVIEW_* typemaps.

Oh, and Brian's description of SWIG is an eminently fair one.

AND, if NumPtr is only for Numeric, you should know that Numeric is no  
longer developed or supported.

On May 17, 2008, at 4:55 PM, Jose Martin 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!

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: wfspotz@sandia.gov **

More information about the Numpy-discussion mailing list