Using cython to accelerate some computations.