chapter five
This chapter covers:
- An introduction to Cython from a data processing perspective
- Using Cython to implement performant NumPy functions
- Writing Cython code for NumPy that can be used with threaded NumPy parallelism
- Write general Cython code that can release the GIL and hence implement true threaded parallelism
Python is slow. The standard implementation is slow and the language dynamic features pay a performance toll. Many Python libraries are performant precisely because they are partially implemented in lower level languages making available efficient data processing algorithms. But sometimes we will need to implement our own high-performance algorithms in something faster than Python. In this chapter we are going to consider Cython, a superset of Python that is converted to C and is substantially more performant than Python.
There are plenty of alternatives—other than Cython—that can be integrated with Python for performance, we will start by a brief overview of the options that are available. After that we will delve into Cython proper.