From the course: Faster pandas

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Compiling Cython

Compiling Cython

From the course: Faster pandas

Start my 1-month free trial

Compiling Cython

- To build a code you will need cython stop. So python -m pip install cython. You will also need a C compiler on your machine. The first step is to write set-up the pyfile. We import set up from setup tools and from cython build we import cythonize. And then we call the setup function which has many arguments. But in this case, we're going to use the minimum version saying ext modules which is extension modules is cythonize of our coding relu. And now we can build it with python setup.py build_ext --inplace. And you can see that python is working and generating the .sl file Let's have a look. We have our relu.c which is the generated C code from relu.pyx And finally we have the .sl which is the shared library which we can import. We also have a build directory which we can ignore. and now we can run ipython. And first let's import the python code. And let's time it relu1.relu(12) This is 295 nanoseconds. Now let's import our cython generated code. So import relu. And you can see it…

Contents