[Pythonmac-SIG] C Extension Scipy/Numpy

2010-02-25 Thread brennsuppa

Hi,

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

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

this throws an error conflicting types for do_anything

regards,
joe
-- 
View this message in context: 
http://old.nabble.com/C-Extension-Scipy-Numpy-tp27714231p27714231.html
Sent from the Python - pythonmac-sig mailing list archive at Nabble.com.

___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG


Re: [Pythonmac-SIG] C Extension Scipy/Numpy

2010-02-25 Thread Zachary Pincus

Hi,

Probably better to:
(1) Ask this on the numpy mailing list, and
(2) Provide a complete, compilable example of the offending code.

Also, you may find it easier to write a pure-C routine and call into  
it using ctypes (getting pointers via numpy arrays' ctypes  
attributes), or alternately, use cython to write the routine.


Zach


On Feb 24, 2010, at 10:28 AM, brennsuppa wrote:



Hi,

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

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

this throws an error conflicting types for do_anything

regards,
joe
--
View this message in context: 
http://old.nabble.com/C-Extension-Scipy-Numpy-tp27714231p27714231.html
Sent from the Python - pythonmac-sig mailing list archive at  
Nabble.com.


___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG


___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG


Re: [Pythonmac-SIG] C Extension Scipy/Numpy

2010-02-25 Thread Chris Barker

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/ORR(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