[Cython] Type inference question
Hi! I'm now trying to make inlined generator expressions work again. And I found strange thing: inlined_generator_expression.pyx: def range_sum(int N): """ >>> sum(range(10)) 45 >>> range_sum(10) 45 """ result = sum(i for i in range(N)) return result 'i' is expected to be integer, but it isn't So I tried simple example and 'i' is inferred as object: def bar(int N): cdef int result = 0 for i in range(N): result += i return result So, I'm wondering should it be inferred as int or not? -- vitja. ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] nested prange
I'm all for allowing it at the Cython level even though we can't emit code for it at the C level (due to C compiler bugs, right?) - Robert On Fri, Nov 25, 2011 at 3:12 AM, mark florisson wrote: > I think we should allow nested prange()s, although it won't invoke > nested OpenMP parallelism now, it still specifies that iterations are > independent which can be useful for optimizations now (e.g. collapsing > two loops into one) and in the future with other backends. Any > thoughts or objections? > ___ > cython-devel mailing list > cython-devel@python.org > http://mail.python.org/mailman/listinfo/cython-devel > ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] Type inference question
On Sat, Nov 26, 2011 at 8:10 AM, Vitja Makarov wrote: > Hi! > > I'm now trying to make inlined generator expressions work again. And I > found strange thing: > > inlined_generator_expression.pyx: > > def range_sum(int N): > """ > >>> sum(range(10)) > 45 > >>> range_sum(10) > 45 > """ > result = sum(i for i in range(N)) > return result > > 'i' is expected to be integer, but it isn't > > So I tried simple example and 'i' is inferred as object: > > def bar(int N): > cdef int result = 0 > for i in range(N): > result += i > return result > > So, I'm wondering should it be inferred as int or not? It's not because it's used in an arithmetic expression that might overflow. You can decorate this with @cython.infer_types(True) or use doubles to get the inference you want. - Robert ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] Type inference question
2011/11/26 Robert Bradshaw : > On Sat, Nov 26, 2011 at 8:10 AM, Vitja Makarov > wrote: >> Hi! >> >> I'm now trying to make inlined generator expressions work again. And I >> found strange thing: >> >> inlined_generator_expression.pyx: >> >> def range_sum(int N): >> """ >> >>> sum(range(10)) >> 45 >> >>> range_sum(10) >> 45 >> """ >> result = sum(i for i in range(N)) >> return result >> >> 'i' is expected to be integer, but it isn't >> >> So I tried simple example and 'i' is inferred as object: >> >> def bar(int N): >> cdef int result = 0 >> for i in range(N): >> result += i >> return result >> >> So, I'm wondering should it be inferred as int or not? > > It's not because it's used in an arithmetic expression that might > overflow. You can decorate this with @cython.infer_types(True) or use > doubles to get the inference you want. > Ok. So I guess something changed after inlined genexps was disabled: https://github.com/cython/cython/blob/master/tests/run/inlined_generator_expressions.pyx#L16 This test relies on integer range. I'm also a little bit concerned about MarkAssignments I think it's better to merge it with CreateControlFlow. For instance, type inference doesn't work for comprehensions and will not work for inlined genexprs. -- vitja. ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] Type inference question
On Sat, Nov 26, 2011 at 11:00 AM, Vitja Makarov wrote: > 2011/11/26 Robert Bradshaw : >> On Sat, Nov 26, 2011 at 8:10 AM, Vitja Makarov >> wrote: >>> Hi! >>> >>> I'm now trying to make inlined generator expressions work again. And I >>> found strange thing: >>> >>> inlined_generator_expression.pyx: >>> >>> def range_sum(int N): >>> """ >>> >>> sum(range(10)) >>> 45 >>> >>> range_sum(10) >>> 45 >>> """ >>> result = sum(i for i in range(N)) >>> return result >>> >>> 'i' is expected to be integer, but it isn't >>> >>> So I tried simple example and 'i' is inferred as object: >>> >>> def bar(int N): >>> cdef int result = 0 >>> for i in range(N): >>> result += i >>> return result >>> >>> So, I'm wondering should it be inferred as int or not? >> >> It's not because it's used in an arithmetic expression that might >> overflow. You can decorate this with @cython.infer_types(True) or use >> doubles to get the inference you want. >> > > Ok. So I guess something changed after inlined genexps was disabled: > > https://github.com/cython/cython/blob/master/tests/run/inlined_generator_expressions.pyx#L16 > > This test relies on integer range. Perhaps. Or perhaps it was implemented in such as way that the arithmetic was not detected (which would have been a bug). > I'm also a little bit concerned about MarkAssignments I think it's > better to merge it with CreateControlFlow. > For instance, type inference doesn't work for comprehensions and will > not work for inlined genexprs. I think it makes sense to merge MarkAssignments into CreateControlFlow; the former was a simple transform before we had any control flow. - Robert ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel