Skip to 0 minutes and 11 secondsIn complex programs it is not always straight forward to see whether you have introduced static typing in the all the relevant parts of your Cython module. However, Cython provides you easy-to-use tool for investigating that. With the Cython annotate tool you can start the Cython with -a followed by the name of your Cython module. What Cython does here, it creates a report about the cythonization process storing it in filename but now with the HTML-form. You can now launch this file with your favourite browser,

Skip to 0 minutes and 58 secondsafter which you can see in yellow all the parts of the program that involve some Python overhead, and with white those parts that translated into the pure C. In this particular case we can see now that for our kernel function here, it is practically all C, only when you return from the function there is some Python overhead involved there. However, if you forget to introduce static typing in some parts of the program, we can look how the report would look like. So let's edit our module a bit, and just remove the static type defintion from the count argument here. Let's save the file and now create the report again with the annotate tool.

Skip to 1 minute and 58 secondsI can launch now this report into a new tab, and if we compare to the previous one here, you can see that now there is in the actual while loop some Python overhead involded, and you can also the see actual code, C code, that this translates, so we can see some Python API calls here, and you can see also that while incrementing the count there is some Python overhead because count no longer is a pure C integer, but a Python integer object.

Skip to 2 minutes and 36 secondsThe Cython annotate tool provides easy way to figure out whether you have introduced static typing in all the relevant parts of the program.

Where to add types?

In complex programs it is not always straight forward to see whether you have introduced static typing in the all the relevant parts of your Cython module.

Cython provides an easy-to-use annotate tool, which allows one to investigate the translation to C with web browser.

Share this video:

This video is from the free online course:

Python in High Performance Computing

Partnership for Advanced Computing in Europe (PRACE)