News for hackers. Stuff that matters.
Re:Using the Cython Compiler to write fast Python code by baltcode on Thursday October 28, 2010 @11:43PM (#1846035)
I used this a long time ago, and from my observations, the biggest gains occurred in loops. (They are the only time Python is really slow anyway.) However, the last time I checked interfacing with numpy and scipy was not supported.
Re:Using the Cython Compiler to write fast Python code by cdavid on Friday October 29, 2010 @12:41AM (#1846166)
Then you checked a very long time ago :) It is quite easy to pass numpy arrays to cython functions. I would say that except in some very special cases, writing raw Python C interface is useless (of course, writing numerical code which is independent of the C API is still very useful). Cython also gives you the benefit of py3x compatibility (cython generates wrappers which can be compiled for both python 2 and python 3).
Re:Using the Cython Compiler to write fast Python code by rdtsc on Friday October 29, 2010 @01:06AM (#1846224)
> I would say that except in some very special cases, writing raw Python C interface is useless ...

I would disagree. Cython is less known and has a learning curve. CPython extension interface is well established and more common. That is not an insignificant advantage.

Do you stop for a couple weeks to learn Cython, and do you have complete confidence in its generated code, or do you just start using something you know and is tried and true? It depends. We chose C Python extensions or just writing hotspots in C in a separate process.

Re:Using the Cython Compiler to write fast Python code by cdavid on Friday October 29, 2010 @06:33PM (#1849327)
The C API also has a learning curve, and is certainly harder than cython. You don't need a couple of weeks to learn cython - I rewrote one small package from ctypes to cython in ~ 1 day, without previous experience in cython.

The problem of C python extensions is that it is so hard to write correctly because of reference counting.

Re:Using the Cython Compiler to write fast Python code by another on Friday October 29, 2010 @12:41AM (#1846167)
I'm not sure of your needs, but there's now reasonable support for efficient interaction with numpy arrays; see, eg

http://docs.cython.org/src/tutorial/numpy.html

and/or

http://conference.scipy.org/proceedings/SciPy2009/paper_2/fu...

Some types of array addressing will take the slower---but still correct---invocation path through Python, but the common form is compiled to direct (albeit strided) array access.

Re:Using the Cython Compiler to write fast Python code by baltcode on Friday October 29, 2010 @02:03AM (#1846334)
Thanks, that looks great! I used to do stuff like that with weave. It would be interesting to see the speed comparison for weave and cython.