Skip to content
This repository was archived by the owner on Apr 24, 2020. It is now read-only.

Commit 8f084ce

Browse files
committed
minor improvements to parallelization lecture
1 parent 7473497 commit 8f084ce

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

source/rst/parallelization.rst

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ For example, let's return to a maximization problem :ref:`discussed previously <
171171
def f(x, y):
172172
return np.cos(x**2 + y**2) / (1 + x**2 + y**2)
173173
174-
grid = np.linspace(-3, 3, 1000)
174+
grid = np.linspace(-3, 3, 5000)
175175
x, y = np.meshgrid(grid, grid)
176176
177-
qe.tic()
178-
np.max(f(x, y))
179-
qe.toc()
177+
.. code-block:: ipython3
178+
179+
%timeit np.max(f(x, y))
180180
181181
If you have a system monitor such as `htop` (Linux/Mac) or `perfmon`
182182
(Windows), then try running this and then observing the load on your CPUs.
@@ -206,14 +206,11 @@ create custom :ref:`ufuncs <ufuncs>` with the `@vectorize
206206
def f_vec(x, y):
207207
return np.cos(x**2 + y**2) / (1 + x**2 + y**2)
208208
209-
grid = np.linspace(-3, 3, 1000)
210-
x, y = np.meshgrid(grid, grid)
211-
212209
np.max(f_vec(x, y)) # Run once to compile
213210
214-
qe.tic()
215-
np.max(f_vec(x, y))
216-
qe.toc()
211+
.. code-block:: ipython3
212+
213+
%timeit np.max(f_vec(x, y))
217214
218215
At least on our machine, the difference in the speed between the
219216
Numba version and the vectorized NumPy version shown above is not large.
@@ -263,11 +260,11 @@ It turns out that we can, by adding some type information plus ``target='paralle
263260
264261
np.max(f_vec(x, y)) # Run once to compile
265262
266-
qe.tic()
267-
np.max(f_vec(x, y))
268-
qe.toc()
263+
.. code-block:: ipython3
264+
265+
%timeit np.max(f_vec(x, y))
269266
270-
Now our code runs significantly faster than the NumPy version!
267+
Now our code runs significantly faster than the NumPy version.
271268

272269

273270

0 commit comments

Comments
 (0)