[Numpy-discussion] SWIG Numpy and C++ extensions

David Froger david.froger@gmail....
Tue Jul 31 15:04:06 CDT 2012


> I'm looking at SWIG/numpy tutorials
They are these tutorials:

Reading numpy.i is also very instructive.

> 1- How do use "apply" for class functions %apply (bla) myobject::foo ?
%apply  is  specified  on  function/method   arguments  names  and  types  only,
never on function names.  So if for example you use:
%apply (int* ARGOUT_ARRAY1, int DIM1) {(int* rangevec, int n)}
it will apply on every functions that have arguments "int* ARGOUT_ARRAY1, int DIM1"

> 2-that's ok if your C++ deals with arrays but what if I actually want to receive the Numpy object so that I can manipulate it directly (or if for example the array isn't contiguous in memory)
> An"dummy"example of foo function I'd like to wrap:
>      void FOO::fooNumpy(PyArrayObject *nparray) {
>       int j;
>       for(j=0;j<nparray->nd;j++) {
> printf("Ok array dim %i has length: %i\n",j,nparray->dimensions[j]);
>       }
>     }
I never do it with Swig, will try to make this example works!


More information about the NumPy-Discussion mailing list