Cython Example

473 days ago by cswiercz

This simple example demonstrates how Cython turns Python-looking code into C. Just click the link to the html file located in the cell output. Then double click on line 12 to see the auto-generated C code. It looks long and complicated but a closer inspection shows that most of what's written are variables names. Buried within you can find something like

exp(pow(x,2))

Take a look at the other lines of code to see otehr examples of how Cython converts to C.

%cython cdef extern from "math.h": double exp(double) double log(double) cdef double x,y,z x = 3 y = log(x**2) # this uses the C math library's "log", not Python's z = exp(y) # this uses the C math library's "exp", not Python's print z