[Numpy-discussion] Numpy + SWIG
Gideon Simpson
gideon.simpson at gmail.com
Mon Jun 4 17:00:29 EDT 2012
There are two types of swig problems that I was hoping to get some help with. First, suppose I have some C function
void f(double *x, int nx, double *y, int ny);
where we input one array, and we output another array, both of which should be the same size.
I have used in my .i file:
%apply(double *IN_ARRAY1, int DIM1){(double *x, int nx)}
%apply(double *ARGOUT_ARRAY1, int DIM1){(double *y, int ny)}
and this produces a workable function. However, it expects, as the functions second argument, the length of the array x. Now, it's easy enough to call:
module.f(x, x.shape[0])
but is there a way to automatically get it to use the length of the array?
The second problem I have is for a function of the fomr
void g(double *x, int nx, double *y, int ny, double *z, int nz);
which evaluates some function g at all (x,y) pairs. The the thing is that nx and ny need not be the same size, but nz should be nx * ny. I'd like to wrap this too, and ideally it would also automatically handle the array lengths, but I'd be happy to have anything right now. I'm also quite comfortable with the idea of packing z as a column array and reshaping it as necessary.
-gideon
More information about the NumPy-Discussion
mailing list