1 | initial version |
Cython (included with Sage) converts Python-like code into C which can then be compiled into a shared-object library and used by Python / Sage. It's intended use is to write code that is easy to use like Python but is optimized to use fast C data types instead of slower Python data structures. However, one could certainly just write Python without any optimizations and have Cython generate the C equivalent.
Create a .pyx
file containing your code and execute
$ sage -cython -a mycythonfile.pyx
This will output a corresponding .c
file which can be compiled into a shared object library and import
ed in Python along with an.html
file that neatly shows the C equivalent of each line of code.
2 | No.2 Revision |
Cython (included with Sage) converts Python-like code into C which can then be compiled into a shared-object library and used by Python / Sage. It's intended use is to write code that is easy to use like Python but is optimized to use fast C data types instead of slower Python data structures. However, one could certainly just write Python without any optimizations and have Cython generate the C equivalent.
Create a .pyx
file containing your code and execute
$ sage -cython -a mycythonfile.pyx
This will output a corresponding .c
file which can be compiled into a shared object library and import
ed in Python along with an.html
file that neatly shows the C equivalent of each line of code.
Be warned that the corresponding C code, though optimized, looks really messy.
For more information on compiling Cython code, take a look at the Cython compilation documentation.