[Cython] Beginner-friendly tickets
Anoop Saldanha
poonaatsoc at gmail.com
Wed Mar 18 18:29:51 CET 2009
Looks like it was available here
http://docs.cython.org/docs/language_basics.html#integer-for-loops and
http://docs.cython.org/docs/pyrex_differences.html#automatic-range-conversion
On Wed, Mar 18, 2009 at 10:23 PM, Anoop Saldanha <poonaatsoc at gmail.com>wrote:
> Thanks Kurt. That was helpful. Looks like the optimization is happening
> at IterationTransform() in the pipeline.
>
>
> On Wed, Mar 18, 2009 at 9:59 PM, Kurt Smith <kwmsmith at gmail.com> wrote:
>
>> 2009/3/18 Anoop Saldanha <poonaatsoc at gmail.com>:
>>
>> [snip]
>>
>> >
>> > But
>> >
>> > cdef int g():
>> > print "g called"
>> > return 5
>> >
>> > def f():
>> > cdef int i
>> > for i in range(g()):
>> > print i
>> > print i
>> >
>> > uses a ForFromStatNode for the "for in" loop!
>>
>> I'm not a core developer, so this is open to correction, but putting
>> in some PrintTree() calls into
>> Cython/Compiler/Main.py:create_pipeline() shows that it starts out as
>> a ForInStatNode and is changed to a ForFromStatNode. Perhaps because
>> cython inferrs that g returns a C int and it triggers the 'range'
>> optimization.
>>
>> Before any transformations:
>>
>> - (root): ModuleNode(pos=(foo.pyx:1:0))
>> - body: StatListNode(pos=(foo.pyx:1:0))
>> - stats[0]: CFuncDefNode(pos=(foo.pyx:1:5))
>> [removing cdef int g() stuff]
>> - stats[1]: DefNode(name="f")
>> - body: StatListNode(pos=(foo.pyx:6:4))
>> - stats[0]: CVarDefNode(pos=(foo.pyx:6:9))
>> - base_type: CSimpleBaseTypeNode(pos=(foo.pyx:6:9))
>> - declarators[0]: CNameDeclaratorNode(pos=(foo.pyx:6:13))
>> - stats[1]: ForInStatNode(pos=(foo.pyx:8:4)) <== starts out as
>> as ForInStatNode
>> [snip rest of def f() function body]
>>
>> After all transformations:
>>
>> - (root): ModuleNode(pos=(foo.pyx:1:0))
>> - body: StatListNode(pos=(foo.pyx:1:0))
>> - stats[0]: CFuncDefNode(pos=(foo.pyx:1:5))
>> [snip func body]
>> - stats[1]: DefNode(name="f")
>> - body: StatListNode(pos=(foo.pyx:6:4))
>> - stats[0]: ForFromStatNode(pos=(foo.pyx:8:4)) <== Changed to
>> a ForFromStatNode.
>> - target: NameNode(type=<CNumericType int>, name="i")
>> - bound1: IntNode(type=<CNumericType long>)
>> - bound2: SimpleCallNode(type=<CNumericType int>)
>> - function: NameNode(type=<CFuncType <CNumericType int>
>> []>, name="g")
>> - step: IntNode(type=<CNumericType long>)
>> - body: StatListNode(pos=(foo.pyx:9:8))
>> - stats[0]: PrintStatNode(pos=(foo.pyx:9:8))
>> - arg_tuple: TupleNode(type=<PyTuple_Type>)
>> - args[0]: CoerceToPyTypeNode(type=<PyObjectType>)
>> - arg: NameNode(type=<CNumericType int>, name="i")
>> - stats[1]: PrintStatNode(pos=(foo.pyx:10:4))
>> - arg_tuple: TupleNode(type=<PyTuple_Type>)
>> - args[0]: CoerceToPyTypeNode(type=<PyObjectType>)
>> - arg: NameNode(type=<CNumericType int>, name="i")
>>
>> Kurt
>> _______________________________________________
>> Cython-dev mailing list
>> Cython-dev at codespeak.net
>> http://codespeak.net/mailman/listinfo/cython-dev
>>
>
>
>
> --
> Regards,
> Anoop S.
>
> People who says, "It's not winning or losing that matters, but
> participation", probably lost.
>
--
Regards,
Anoop S.
People who says, "It's not winning or losing that matters, but
participation", probably lost.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/cython-dev/attachments/20090318/787ab8e2/attachment-0001.htm
More information about the Cython-dev
mailing list