Skip to content

Commit 032a2a2

Browse files
committed
Typo fixes and small enhancements in week 3
1 parent f12acb9 commit 032a2a2

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

docs/mooc/using-compiled-code/interfacing-c-with-cffi.md

+3
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,6 @@ bptr = ffi.cast("double *", ffi.from_buffer(b))
174174
175175
lib.add(aptr, bptr, cptr, len(a))
176176
~~~
177+
178+
Beware that `aptr`, `bptr` and `cptr` resemble now in many ways C pointers,
179+
and if you deal carelessly with them you can get Segmentation faults!

docs/mooc/using-compiled-code/interfacing-c-with-cython.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ cdef extern void add(double *a, double *b, double *c, int n)
2323
~~~
2424

2525
one could call `add` function within that file. In addition, the actual
26-
library or source needs to be included in **setup.py** when building the
27-
extension module with Cython.
26+
library or source implementing the function needs to be included in
27+
**setup.py** when building the extension module with Cython.
2828

2929
With the above construct, Cython will add the declaration to the generated
30-
.c file. However, when using libraries it is preferrable to have the actual
30+
.c file. However, when using libraries it is preferable to have the actual
3131
library header included in the generated file. This can be achieved with the
3232
following construct:
3333

docs/mooc/using-compiled-code/using-static-typing.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ types. More information can be found in the
119119

120120
## Static typing in Mandelbrot kernel
121121

122-
Let's investigate possible speed-up by introducing static typing to the
123-
**kernel** function in the **mandelbrot.pyx** module.
122+
We did earlier a performance analysis of Mandelbrot fractal which revealed
123+
that the **kernel** function in module **mandelbrot.py** was the most time
124+
critical one. Thus, let's make **mandelbrot.py** into Cython module
125+
**mandelbrot.pyx** and introducing static typing to the function
126+
**kernel**.
124127

125128
Pure Python version was:
126129

@@ -151,7 +154,8 @@ def kernel(double zr, double zi, double cr, double ci, double lim, int cutoff):
151154
return count
152155
~~~
153156

154-
When measuring now the performance, we obtain the following results:
157+
When comparing the performance of pure Python and Cythonized versions,
158+
we obtain the following results:
155159

156160
- Pure Python: 0.57 s
157161
- Static type declarations in the kernel: 14 ms

0 commit comments

Comments
 (0)