Josh Ayers
unread,May 18, 2013, 8:01:09 PM5/18/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cython...@googlegroups.com
I just noticed that a for-loop using the standard Python range construct isn't optimized to C-code if the step is a run-time variable. It is optimized if the step parameter is a compile-time constant, or if the old Pyrex style for-loop syntax is used. I tested with Cython 0.18 and 0.19.1 and both behaved the same way.
Here's a minimal example.
DEF STEP = 2
def loops():
cdef int i, start = 0, stop = 10, step = 2
for i in range(start, stop, step): # generates Python loop
print(i)
for i in range(start, stop, STEP): # generates C loop
print(i)
for i from start <= i < stop by step: # generates C loop
print(i)
Is this a bug?
Thanks,
Josh Ayers