brennsuppa wrote:
I want to gain performance by using C for the computation of some arrays.
To do that I used this as a help:
http://www.scipy.org/Cookbook/C_Extensions/NumPy_arrays

I highly recommend that you use Cython instead:

http://wiki.cython.org/tutorials/numpy

It is much easier, and you are much more likely to make mistakes with reference counting, etc, if you do it by hand. Trust me on this.

With Cython, you can either do all your calculations with Cython, or have C routines that do the real work, and use Cython to call them. I'd do the former unless your C code is already written (and not trivial). In either case, Cython can handle the conversion from python types to C types, and all the reference counting for you.


Now I want to wirte a subroutine for the calculations with several arrays.
But I don't know how to pass the arrays to the subroutine.

e.g. i have cin1, cin2, cin3, cin4 and cout

cout = do_anything(cin1, cin2, cin3, cin4)

and do_anything would be like:

double **do_anything(cin1[][n], cin2[][n], cin3[][n], cin4[][n])

for rows
for columns
add cin1,cin2,cin3,cin4
return value

Trivial in Cython -- in straight C, you need to pass in the arrays as PyObjects, check if they are the type of arrays you want, and then get the pointers to the data blocks for you to pass to your c function.

Cython will do (almost) all of that for you.

-Chris


--
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.bar...@noaa.gov
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to