[Numpy-discussion] swig numpy2carray converters

Georg Holzmann grh@mur...
Mon Nov 26 01:59:53 CST 2007


Hallo!

> First, my plan is to add to numpy.i, typemaps for signatures like the 
> following:
> 
>     %typemap(argout) (double** ARGOUT_ARRAY1, int* DIM1)
> 
> It is important to note that even though the same argument *names* are 
> used, this is a different typemap signature than
> 
>     %typemap(argout) (double* ARGOUT_ARRAY1, int DIM1)
> 
> and thus can have (logically) different implementations.  For the 
> latter, the typemap allocates a new numpy array and passes the buffer 
> pointer and dimension in; for the former, the buffer pointer and 
> dimension will be obtained from the wrapped function and used to build a 
> new numpy array.

Hm ... maybe it is more clear for users then, if the new typemap has a 
different name ?
In example ARRAY_VIEW1, or something else with "VIEW" (although it's not 
really a view ?) ?

> As for having a COPY version of the first typemap signature (in addition 
> to the non-copy, or "view" version), I currently do not plan to do 
[...]
> The example Georg gives in his link below is not a counter-example to 
> this.  He provides two methods,
> 
>     void getBigData(double **mtx, int *rows, int *cols)
>     void getBigDataCopy(double **cpmtx, int *cprows, int *cpcols)
> 
> but in addition to the same argument types, they have the exact same 
> implementation.  The only thing that is different is the names of the 
> arguments, which is clearly so that we can apply different swig typemaps 
> to the two methods.  I submit that you will not find a class written by 
> someone else that will be designed this way.  You will only find it if 

Yes this copy method was only for demonstration - I also did not use 
this method for my "real" code.
One can simply call .copy() in python ...

LG
Georg


More information about the Numpy-discussion mailing list