@@ -10,7 +10,8 @@ and your new friends (among others) are named "vectors", "arrays", "views" or
1010Simple example
1111--------------
1212
13- Let's take a very simple example, random walk.
13+ Let's take a very simple example, random walk. (You can execute any code below
14+ from the `code ` folder, ideally inside an IPython session or Jupyter notebook.)
1415
1516One possible object oriented approach would be to define a `RandomWalker ` class
1617and to write with a walk method that would return current position after each
@@ -46,8 +47,8 @@ Benchmarking gives us:
4647 **Functional approach **
4748
4849For such a simple problem, we can probably save the class definition and
49- concentrate only on the walk method that compute successive positions after
50- each random steps .
50+ concentrate only on the walk method that computes successive positions after
51+ each random step .
5152
5253.. code :: python
5354
@@ -68,7 +69,7 @@ we saved probably come from the inner Python object-oriented machinery.
6869.. code :: pycon
6970
7071 >>> from tools import timeit
71- >>> timeit("random_walk(n=10000)] ", globals())
72+ >>> timeit("random_walk(n=10000)", globals())
7273 10 loops, best of 3: 15.6 msec per loop
7374
7475
@@ -78,7 +79,7 @@ But we can do better using the `itertools
7879<https://docs.python.org/3.6/library/itertools.html> `_ Python module that
7980offers a set of functions creating iterators for efficient looping. If we
8081observe that a random walk is an accumulation of steps, we can rewrite the
81- function as:
82+ function as follows :
8283
8384.. code :: python
8485
@@ -99,7 +100,7 @@ things faster:
99100.. code :: pycon
100101
101102 >>> from tools import timeit
102- >>> timeit("random_walk_faster(n=10000)] ", globals())
103+ >>> timeit("random_walk_faster(n=10000)", globals())
103104 10 loops, best of 3: 8.21 msec per loop
104105
105106 We gained 50% of computation-time compared to the previous version, not so
@@ -119,11 +120,11 @@ Not too difficult, but we gained a factor 500x using numpy:
119120.. code :: pycon
120121
121122 >>> from tools import timeit
122- >>> timeit("random_walk_faster (n=10000)] ", globals())
123+ >>> timeit("random_walk_fastest (n=10000)", globals())
123124 1000 loops, best of 3: 14 usec per loop
124125
125126
126- This book is about vectorization, be it at the level of code or problem. We'll
127+ This book is about vectorization, be it at the code or problem level . We'll
127128see this difference is important before looking at custom vectorization.
128129
129130
0 commit comments