Using Cython with Jupyter
Optimizing Cython code requires substantial trial and error. Fortunately, Cython tools can be conveniently accessed through Jupyter Notebooks for a more streamlined and integrated experience.
You can launch a notebook session by typing jupyter notebook
in the command line, and you can load the Cython magic by typing %load_ext cython
in a cell.
As mentioned earlier, the %%cython
magic can be used to compile and load the Cython code inside the current session. As an example, we may copy the contents of the cheb.py
file into a notebook cell, like this:
%%cython import numpy as np cdef int max(int a, int b): return a if a > b else b cdef int chebyshev(int x1, int y1, int x2, int y2): return max(abs(x1 - x2), abs(y1 - y2)) def c_benchmark...