for loop with variable step not optimized
2013-05-19 00:01:09 GMT
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
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
RSS Feed