[Cython] [cython-users] Possible enumerate automatic conversion

Stefan Behnel stefan_ml at behnel.de
Wed Apr 17 13:47:25 CEST 2013


Daniele Nicolodi, 16.04.2013 15:09:
> would it be desirable to have an enumerate() automatic conversion
> similar to the range() conversion when the enumerated iterable is a C
> array or a numpy array?
> 
> http://docs.cython.org/src/userguide/pyrex_differences.html#automatic-range-conversion

enumerate() is optimised since something like 0.13 or so, maybe longer. It
certainly works for char* and maybe also other C arrays.


> I imagine that detecting the opportunity for the optimization may be a
> bit tricky, but it should not be much different than a combination of
> what is done for iteration over a C array and for the range() function.

Yes, the tricky bit is to get the iterable through the type analysis
without coercion errors. This couldn't easily be done at the time but
became possible with my recent analyse_types() phase changes.

Essentially, for-loop optimisations can now be moved into the type analysis
phase and take the type of the iterable into account without running into
accidental coercion errors.

I'm not sure yet if this is the right way to do it - maybe we still want an
explicit transformation instead.

In any case, the right place to discuss this is the cython-devel mailing
list, not the users mailing list.

Stefan



More information about the cython-devel mailing list