Looks like it was available here <a href="http://docs.cython.org/docs/language_basics.html#integer-for-loops">http://docs.cython.org/docs/language_basics.html#integer-for-loops</a> and <a href="http://docs.cython.org/docs/pyrex_differences.html#automatic-range-conversion">http://docs.cython.org/docs/pyrex_differences.html#automatic-range-conversion</a><br>
<br><div class="gmail_quote">On Wed, Mar 18, 2009 at 10:23 PM, Anoop Saldanha <span dir="ltr"><<a href="mailto:poonaatsoc@gmail.com">poonaatsoc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks Kurt. That was helpful. Looks like the optimization is happening at IterationTransform() in the pipeline.<div><div></div><div class="h5"><br><br><div class="gmail_quote">On Wed, Mar 18, 2009 at 9:59 PM, Kurt Smith <span dir="ltr"><<a href="mailto:kwmsmith@gmail.com" target="_blank">kwmsmith@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2009/3/18 Anoop Saldanha <<a href="mailto:poonaatsoc@gmail.com" target="_blank">poonaatsoc@gmail.com</a>>:<br>
<br>
[snip]<br>
<div><br>
><br>
> But<br>
><br>
> cdef int g():<br>
> print "g called"<br>
> return 5<br>
><br>
> def f():<br>
> cdef int i<br>
> for i in range(g()):<br>
> print i<br>
> print i<br>
><br>
> uses a ForFromStatNode for the "for in" loop!<br>
<br>
</div>I'm not a core developer, so this is open to correction, but putting<br>
in some PrintTree() calls into<br>
Cython/Compiler/Main.py:create_pipeline() shows that it starts out as<br>
a ForInStatNode and is changed to a ForFromStatNode. Perhaps because<br>
cython inferrs that g returns a C int and it triggers the 'range'<br>
optimization.<br>
<br>
Before any transformations:<br>
<br>
- (root): ModuleNode(pos=(foo.pyx:1:0))<br>
- body: StatListNode(pos=(foo.pyx:1:0))<br>
- stats[0]: CFuncDefNode(pos=(foo.pyx:1:5))<br>
[removing cdef int g() stuff]<br>
- stats[1]: DefNode(name="f")<br>
- body: StatListNode(pos=(foo.pyx:6:4))<br>
- stats[0]: CVarDefNode(pos=(foo.pyx:6:9))<br>
- base_type: CSimpleBaseTypeNode(pos=(foo.pyx:6:9))<br>
- declarators[0]: CNameDeclaratorNode(pos=(foo.pyx:6:13))<br>
- stats[1]: ForInStatNode(pos=(foo.pyx:8:4)) <== starts out as<br>
as ForInStatNode<br>
[snip rest of def f() function body]<br>
<br>
After all transformations:<br>
<br>
- (root): ModuleNode(pos=(foo.pyx:1:0))<br>
- body: StatListNode(pos=(foo.pyx:1:0))<br>
- stats[0]: CFuncDefNode(pos=(foo.pyx:1:5))<br>
[snip func body]<br>
- stats[1]: DefNode(name="f")<br>
- body: StatListNode(pos=(foo.pyx:6:4))<br>
- stats[0]: ForFromStatNode(pos=(foo.pyx:8:4)) <== Changed to<br>
a ForFromStatNode.<br>
- target: NameNode(type=<CNumericType int>, name="i")<br>
- bound1: IntNode(type=<CNumericType long>)<br>
- bound2: SimpleCallNode(type=<CNumericType int>)<br>
- function: NameNode(type=<CFuncType <CNumericType int><br>
[]>, name="g")<br>
- step: IntNode(type=<CNumericType long>)<br>
- body: StatListNode(pos=(foo.pyx:9:8))<br>
- stats[0]: PrintStatNode(pos=(foo.pyx:9:8))<br>
- arg_tuple: TupleNode(type=<PyTuple_Type>)<br>
- args[0]: CoerceToPyTypeNode(type=<PyObjectType>)<br>
- arg: NameNode(type=<CNumericType int>, name="i")<br>
- stats[1]: PrintStatNode(pos=(foo.pyx:10:4))<br>
- arg_tuple: TupleNode(type=<PyTuple_Type>)<br>
- args[0]: CoerceToPyTypeNode(type=<PyObjectType>)<br>
- arg: NameNode(type=<CNumericType int>, name="i")<br>
<font color="#888888"><br>
Kurt<br>
</font><div><div></div><div>_______________________________________________<br>
Cython-dev mailing list<br>
<a href="mailto:Cython-dev@codespeak.net" target="_blank">Cython-dev@codespeak.net</a><br>
<a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div><div><div></div><div class="h5">-- <br>Regards,<br>Anoop S.<br><br>People who says, "It's not winning or losing that matters, but participation", probably lost.<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Anoop S.<br><br>People who says, "It's not winning or losing that matters, but participation", probably lost.<br>