[Numpy-discussion] Psyco MA?
falted at openlc.org
Mon Feb 10 23:24:01 CST 2003
A Dissabte 08 Febrer 2003 11:54, Joachim Saul va escriure:
> Please check out the Pyrex doc. It's actually very easy right now,
> *if* you can live without "sequence operators" such as slicing,
> list comprehensions... but this is going to be supported, again
> according to the doc.
Why you are saying that slicing is not supported?. I've checked them (as
python expressions, of course) and work well. May be you are referring to
cdef'd c-typed arrays in Pyrex?. I think this should be a dangerous thing
that can make the pointer arithmetic to slow down because of the additional
required checks in the slice range.
> For example, I may call (C-like)
> arr = PyArray_FromDims(1, &n, PyArray_DOUBLE)
> but could have also used a corresponding Python construct like
> from Numeric import zeros
> arr = zeros(n, 'd')
> I expect the latter to be slower (not tested), but one can take
> Python code "as is" and "compile" it using Pyrex.
I was curious about that and tested it in my Pentium 4 @ 2 GHz laptop and
for small n (just to look for overhead). The C-like call takes 26 us and the
Python-like takes 52 us.
Generally speaking, you can expect an overhead of 20 us (a bit more as you
pass more parameters) calling Python functions (or Python-like functions
inside Pyrex) from Pyrex, compared to when you use a C-API to call the
corresponding C function. In fact, calling a C-function (or a cdef Pyrex
function) from Pyrex takes no more time than calling from C to C: on my
laptop both scores at 0.5 us.
The fact that calling C functions from Pyrex has not a significant overhead
(compared with calls from C to C) plus the fact that Pyrex offers a C
integer loop makes Pyrex so appealing for linear algebra optimizations, not
only as a "glue" language.
Another advantage is that with Pyrex you can define classes with a mix of
C-type and Python-type attributes. This can be very handy to obtain a
compact representation of objects (whenever you do not need to access the
C-typed ones from Python, but anyway, you can always use accessors if
More information about the Numpy-discussion