Cython

Perhaps you come from a c++ programming background and you still have this nagging feeling in the back of your head about Python being interpreted, and how that could mess up speed performance of your code. Never fear, Cython to the rescue.

Cython is an optimizing static compiler for the Python programming language. It gives you the combined power of Python and C.

Cython is a superset of the python language that supports calling C functions and declaring C data types on variables and class attributes. The benefit of these added features is that it allows the compiler to generate very efficient C code from Cython code. You generate C code once, and then compile it with the C compiler of your choice.

So, Cython makes it easy to wrap external C libraries in a form so that you can then use them in a Python program. Conversely, you could embed CPython code into an existing C application i believe, which is eye opening. And of course you can use it to speed up your Python code if you need it to run faster.

Check out the Cython Documentation Wiki.

Everyone's old favorite fallback, a Mandelbrot fractal generator code example is there to take for a test drive.

As an aside, MIT Media Lab professor and later Director Walter Bender once told me he punished any of his students he caught playing with Mandelbrot fractal code. Imagine that. I guess they better not try out the Cython examples.

Comments

Popular posts from this blog

CycleGAN: a GAN architecture for learning unpaired image to image transformations

Pix2Pix: a GAN architecture for image to image transformation

Smart Fabrics