[Cython] Comments on example code?
Gabriel Gellner
ggellner at uoguelph.ca
Tue Nov 25 17:26:08 CET 2008
> However, I'll also note that the usual way to get high performance with
> NumPy is to reformulate the computation so that you do it all in
> parallell. If you are evaluating this using a grid with n=1000 or similar,
> then as long as you code things so that all operations happen "in
> parallell" then you could code it in pure Python if you wished and it
> would still be at least comparable to Fortran.
>
> I.e. to avoid all the call overheads etc., it pays off to rather do:
>
> gridvalues = eval_func(gridpts)
>
> than
>
> for i in range(..):
> gridvalues[i] = eval_func(gridpts[i])
>
> and continue in the same fashion all the way down. Wherever your loop is,
> there's your problem...
>
True, but I like loops :-) I find vectorized code quickly becomes unreadable
(and awkward to write). I would rather resort to C or Fortran if this is too
much of an issue. I find the best tradeoff is to use tools like f2py and
Cython to decrease the call overhead, I can live with the other slowdowns.
Gabriel
More information about the Cython-dev
mailing list