Re: [Pythonmac-SIG] [ C Extension Scipy/Numpy
I highly recommend that you use Cython instead: 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. There are a few version I tried, but because of the very high mathematical effort I need the fastest solution, wich is doing it by hand. I have a C-Version already - but I will try Cython again by calling my C routines. Thank you so far ;) joe ___ 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
I highly recommend that you use Cython instead: 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. There are a few version I tried, but because of the very high mathematical effort I need the fastest solution, wich is doing it by hand. I have a C-Version already - but I will try Cython again by calling my C routines. If you already have the C code compiled into a shared library, calling into the library with ctypes might be even easier. Especially since numpy arrays have handy attributes for getting pointers-to-data as ctypes objects. Zach ___ 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] C Extension Scipy/Numpy
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
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
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