Sorry for no link -- I was using the PDF...which looks like it's not actually the newest version of the docs (says for cython 0.11.2). Here's the link <http://docs.cython.org/src/userguide/pyrex_differences.html#id1> in the online docs. And no, it doesn't really say much...
This will convert statements of the form for i in range(...) to for i from > ... when i is any cdef’d integer type, and the direction (i.e. sign of step) can be determined. On Mon, Jun 28, 2010 at 9:29 AM, Stefan Behnel <[email protected]> wrote: > Jared Forsyth, 28.06.2010 17:04: > > In the manual, it states that "for i in range(...)" gets automatically > > converted to "for i from..." for performance benefits. > > Sounds like you didn't read on from the point where it said that. If that's > really all it says, please provide a link to the docs, so that we can fix > it. > > > > But it doesn't... I've tried > > > > cdef int a=5 > > for i in range(a):pass > > > > and > > > > for i in range(10):pass > > > > and neither are converted. Is the documentation wrong? [it seems like at > > least the second one should be optimized] > > You didn't state which Cython version you are using, so I assume it's > 0.12.1, which doesn't automatically optimise these things yet. You have to > explicitly tell it that it's safe to restrict 'i' to a C integer in order > to let it break the normal Python semantics of your code. > > Cython 0.13 will recognise the second case, though, and I think even the > first one. Then, the C compiler should be able to drop the above loops as > dead code, as expected. > > Stefan > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev >
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
