@@ -22,9 +22,9 @@ Extending Python with Cython
2222 Using Cython requires that you have a working environment for compiling
2323 C code. This goes beyond the software requirements for this course, so the
2424 teaching will be given in form of demonstrations and no exercises.
25- You may still follow along with the code examples if you have a C compiler
26- installed, in which case you can install Cython to your Conda environment
27- with `conda install cython `.
25+ You may still follow along with the code examples but you will need to have
26+ Cython and a working C compiler available. You can install both to your
27+ Conda environment with `conda install -c conda-forge cython c-compiler `.
2828
2929
3030Python and performance
@@ -66,12 +66,13 @@ performance at runtime.
6666Scientific programs often include computationally expensive sections (e.g.
6767simulations of any kind). So how do we make Python execute our code faster in
6868these situations? Well that's the neat part: we don't! Instead, we write the
69- performance critical parts in a faster language and make them usable from
70- Python.
69+ performance critical parts in a faster language and make them usable
70+ from Python.
7171
72- This is called extending Python, and usually involves writing C-code
73- with Python-specific boilerplate and compiling this as a shared library, which
74- in this context is called a **Python extension module **.
72+ This is called extending Python, and usually boils down to writing C-code
73+ with Python-specific boilerplate, or using a specialized tool for generating
74+ such C code from Python code (so-called *transpilers *). The C-code is compiled
75+ into a shared library, in this context called a **Python extension module **.
7576Most scientific Python libraries (Numpy, Scipy etc) do exactly this: their
7677computationally intensive parts are either written in a compiled language,
7778or they call an external library written in such language.
@@ -197,8 +198,8 @@ We can Cythonize cell contents using the magic `%%cython`:
197198
198199 The compiled function can then be called from other cells.
199200
200- There is also `%%cython --annotate ` which is useful for analyzing the
201- generated C code.
201+ There is also `%%cython --annotate ` (or ` %%cython -a ` for short) which is
202+ useful for analyzing the generated C code.
202203
203204
204205Adding static type information
@@ -259,14 +260,6 @@ int, float float, double
259260str/bytes char \*
260261================= =============
261262
262- ============= ===============
263- From C types To Python types
264- ============= ===============
265- int, long int
266- float, double float
267- char \* str/bytes
268- ============= ===============
269-
270263
271264Using Numpy arrays with Cython
272265------------------------------
0 commit comments