[Numpy-discussion] Right way of looping throught ndarrays using Cython

Robert Kern robert.kern@gmail....
Fri Jun 20 14:07:08 CDT 2008


On Fri, Jun 20, 2008 at 09:17, Gael Varoquaux
<gael.varoquaux@normalesup.org> wrote:
> Hi,
>
> I am trying to figure the right way of looping throught ndarrays using
> Cython, currently. Things seem to have evolved a bit compared to what
> some documents on the web claim (eg "for i from 0<=i<n" does not seem
> faster than "for i in range(n)"). I know there is integration of pex with
> cython on the horizon, but it is not there yet, and I don't want to
> commit to a moving target.
>
> Does somebody have a example of fast looping through ndarrays using
> modern Cython idioms?

If you're using normal Python indexing, then that's where all your
time is being spent. You need to grab the actual .data pointer and do
C indexing to get speed. Can you show us the code you are timing?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco


More information about the Numpy-discussion mailing list