[Numpy-discussion] Numpy + SWIG

Chris Barker chris.barker@noaa....
Mon Jun 4 17:01:51 CDT 2012


HAVe you discovered the numpy.i interface files?

I haven't done SWIG in a while, but they should take care of at least
some of this for you.

They used to be distributed with numpy (in docs?), but some googling
should find then in any case.

-Chris



On Mon, Jun 4, 2012 at 2:00 PM, Gideon Simpson <gideon.simpson@gmail.com> wrote:
> 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
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the NumPy-Discussion mailing list