summaryrefslogtreecommitdiff
path: root/docs/src/tutorial/numpy.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/src/tutorial/numpy.rst')
-rw-r--r--docs/src/tutorial/numpy.rst18
1 files changed, 14 insertions, 4 deletions
diff --git a/docs/src/tutorial/numpy.rst b/docs/src/tutorial/numpy.rst
index 5fa205976..0a5535da6 100644
--- a/docs/src/tutorial/numpy.rst
+++ b/docs/src/tutorial/numpy.rst
@@ -28,7 +28,7 @@ systems, it will be :file:`yourmod.pyd`). We
run a Python session to test both the Python version (imported from
``.py``-file) and the compiled Cython module.
-.. sourcecode:: ipython
+.. code-block:: ipythonconsole
In [1]: import numpy as np
In [2]: import convolve_py
@@ -69,7 +69,7 @@ compatibility. Consider this code (*read the comments!*) :
After building this and continuing my (very informal) benchmarks, I get:
-.. sourcecode:: ipython
+.. code-block:: ipythonconsole
In [21]: import convolve2
In [22]: %timeit -n2 -r3 convolve2.naive_convolve(f, g)
@@ -97,7 +97,7 @@ These are the needed changes::
Usage:
-.. sourcecode:: ipython
+.. code-block:: ipythonconsole
In [18]: import convolve3
In [19]: %timeit -n3 -r100 convolve3.naive_convolve(f, g)
@@ -143,7 +143,7 @@ if we try to actually use negative indices with this disabled.
The function call overhead now starts to play a role, so we compare the latter
two examples with larger N:
-.. sourcecode:: ipython
+.. code-block:: ipythonconsole
In [11]: %timeit -n3 -r100 convolve4.naive_convolve(f, g)
3 loops, best of 100: 5.97 ms per loop
@@ -170,6 +170,16 @@ function call.)
The actual rules are a bit more complicated but the main message is clear:
Do not use typed objects without knowing that they are not set to None.
+What typing does not do
+=======================
+
+The main purpose of typing things as :obj:`ndarray` is to allow efficient
+indexing of single elements, and to speed up access to a small number of
+attributes such as ``.shape``. Typing does not allow Cython to speed
+up mathematical operations on the whole array (for example, adding two arrays
+together). Typing does not allow Cython to speed up calls to Numpy global
+functions or to methods of the array.
+
More generic code
==================