[Python-ideas] A General Outline for Just-in-Time Acceleration of Python

Joseph Martinot-Lagarde joseph.martinot-lagarde at m4x.org
Sat Jun 14 09:38:00 CEST 2014


Le 14/06/2014 09:30, David Mertz a écrit :
> On Fri, Jun 13, 2014 at 11:54 PM, Joseph Martinot-Lagarde
> <joseph.martinot-lagarde at m4x.org
> <mailto:joseph.martinot-lagarde at m4x.org>> wrote:
>
>     Cython compiles all python, it is not restricted.
>
>
> Well, kinda yes and no.  You are correct of course, that anything that
> you can execute with 'python someprog' you can compile with 'cython
> someprog'.  However, there is an obvious sense in which adding an
> annotation (which is, of course, a syntax error for Python itself)
> "restricts" the code in Cython.  E.g.:
>
>     def silly():
>          cdef int n, i
>          for i in range(10):
>              if i < 5:
>                  n = i + 1
>              else:
>                  n = str(i)
>
> This *silly* function isn't really Python code at all, of course.  But
> if you ignore the annotation, it would be--pointless code, but valid. As
> soon as you add the annotation, you *restrict* the type of code you can
> write in the scope of the annotation.
>

Yeah, the point is that *you* restrict, not cython. From your previous 
post I understood that you meant "pypy runs all python but cython 
doesn't, it is restricted".

I use numpy regularely, and in this case it is the other way around: I 
can optimize my code using cython but I can't run it with pypy at all.

---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com




More information about the Python-ideas mailing list