[Cython] Fix for #196 (for loop bug)
Stefan Behnel
stefan_ml at behnel.de
Sun Feb 8 12:45:40 CET 2009
Hi,
Magnus Lie Hetland wrote:
> Should I upload a patch to the tracker?
Sure, that will allow us to take a look at it and compare it to the
while-loop alternative. Just use "hg export" to keep the meta data.
> it occurred to me that it might be
> cleaner to just ditch the for loop than to undo its semantics. It
> won't help on the extra check needed to see if we assign to the loop
> variable at all (i.e., what I'm doing here), but by using a while-loop
> with the proper test, we should be able to avoid the spurious
> increment and the "undo" operation. Worth a shot?
That's my impression, too. I attached an old (incomplete) patch I had lying
around, don't know if it's still any good. Generating a straight
WhileStatNode instead might already do the right thing (and be less
invasive, given that we are nearing a release). See the methods of the
IterationTransform class in Optimize.py for that.
> Or do C compilers
> somehow rely on the use of for loops for some kind of optimization
> inference or something?
No idea. But I doubt that a while loop would be slower than the equivalent
for loop. Plus, we need to fix the semantics here, which is more important
than the last bit of performance.
> there also seemed to be a problem when running
> with the refnanny.
Could you be a bit more specific here? :)
> the tests work without the refnanny (except for
> the NumPy stuff, which all fails because I haven't properly installed
> NumPy at the moment;
It should actually check for numpy being installed and just skip the test
if not. At least, that's what it does here.
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: general_loop_node.patch
Type: text/x-patch
Size: 3149 bytes
Desc: not available
Url : http://codespeak.net/pipermail/cython-dev/attachments/20090208/f71279d7/attachment.bin
More information about the Cython-dev
mailing list