Re: [f2py] f2py-users Digest, Vol 63, Issue 4
Daniel Welling <[email protected]>
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Pearu's suggestion definitely works. I did find, however, that I needed to transpose my numpy arrays before passing them off to my C function. Thanks for the help; this is a huge speed up in field line tracing! -dw On Sun, May 30, 2010 at 3:00 AM, <f2py-users-request-Y4l6ocDipWCuvFJfX82//[email protected]> wrote: > Send f2py-users mailing list submissions to > f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://cens.ioc.ee/mailman/listinfo/f2py-users > or, via email, send a message with subject or body 'help' to > f2py-users-request-Y4l6ocDipWCuvFJfX82//[email protected] > > You can reach the person managing the list at > f2py-users-owner-Y4l6ocDipWCuvFJfX82//[email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of f2py-users digest..." > > > Today's Topics: > > 1. Re: f2py, C, and multidimensional arrays. (Josef Koller) > 2. Re: f2py, C, and multidimensional arrays. (Pearu Peterson) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 29 May 2010 11:50:02 -0600 > From: Josef Koller <[email protected]> > Subject: Re: [f2py] f2py, C, and multidimensional arrays. > To: For users of the f2py program <f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]> > Message-ID: <837CB1AB-C098-495A-A205-71861DD6F0AB-YOWKrPYUwWM@public.gmane.org> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > why not use SWIG? ~Josef > > On May 28, 2010, at 11:41 PM, Daniel Welling wrote: > > > Greetings. I am new to F2py and am trying to use it to wrap some > > simple C functions. I've had success with scalars and vectors, but > > cannot get any multidimensional arrays to work correctly. An example: > > > > /* bar.c */ > > void bar(int n, int m, double **x) { > > int i, j; > > for (i=0; i<n; i++) > > for (j=0; j<m; j++) > > printf("Position %i, %i = %.3f\n", i, j, x[i][j]); > > } > > > > ! wrapper m.pyf > > python module m > > interface > > subroutine bar(n, m, x) > > intent(c) bar > > intent(c) > > integer intent() :: n > > integer intent() :: m > > double precision intent(in) :: x(n,m) > > end subroutine bar > > end interface > > end python module m > > > > Build shared object: > > $ f2py2.5 foo.c foo.pyf -c > > > > Try to run it: > > >>>import m > > >>>import numpy as np > > >>>dog = np.zeros((0,0)) > > >>>m.bar(dog) > > Bus error > > > > And that's it. It drops me out of ipython/python shell and back to > > the bash prompt. I cannot find any examples similar to this, nor > > any mailing list threads on this topic. Does anyone have any > > experience with such examples? > > > > Thanks for your help. > > _______________________________________________ > > f2py-users mailing list > > f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] > > http://cens.ioc.ee/mailman/listinfo/f2py-users > > -- > Josef Koller, Ph.D. (TSPA/Correspondence) > Space Science and Applications, ISR-1, MS D466 > Los Alamos National Laboratory, NM 87545-1663 > Phone: (505) 665 3399 http://www.koller.info > Fax: (505) 665 7395 email: [email protected] > > > > > > > > > > ------------------------------ > > Message: 2 > Date: Sun, 30 May 2010 00:14:52 +0300 > From: Pearu Peterson <[email protected]> > Subject: Re: [f2py] f2py, C, and multidimensional arrays. > To: For users of the f2py program <f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]> > Message-ID: <4C0183CC.1060408-Y4l6ocDipWCuvFJfX82//[email protected]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > > > Daniel Welling wrote: > > Greetings. I am new to F2py and am trying to use it to wrap some simple > > C functions. I've had success with scalars and vectors, but cannot get > > any multidimensional arrays to work correctly. An example: > > > > /* bar.c */ > > void bar(int n, int m, double **x) { > ^-- f2py cannot wrap C functions > that have pointer to pointers arguments. A rule of thumb is that > f2py can wrap C functions that can be called from Fortran. This > example is not such a function. Try wrapping the following > example with the same m.pyf file: > > void bar(int n, int m, double *x) > { > int i, j; > for (i=0; i<n; i++) > for (j=0; j<m; j++) > printf("Position %i, %i = %.3f\n", i, j, (x+i*m)[j]); > } > > Pearu > > > > ------------------------------ > > _______________________________________________ > f2py-users mailing list > f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] > http://cens.ioc.ee/mailman/listinfo/f2py-users > > > End of f2py-users Digest, Vol 63, Issue 4 > ***************************************** > _______________________________________________ f2py-users mailing list f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] http://cens.ioc.ee/mailman/listinfo/f2py-users