@@ -171,12 +171,12 @@ For example, let's return to a maximization problem :ref:`discussed previously <
171
171
def f(x, y):
172
172
return np.cos(x**2 + y**2) / (1 + x**2 + y**2)
173
173
174
- grid = np.linspace(-3, 3, 1000 )
174
+ grid = np.linspace(-3, 3, 5000 )
175
175
x, y = np.meshgrid(grid, grid)
176
176
177
- qe.tic()
178
- np.max(f(x, y))
179
- qe.toc( )
177
+ .. code-block :: ipython3
178
+
179
+ %timeit np.max(f(x, y) )
180
180
181
181
If you have a system monitor such as `htop ` (Linux/Mac) or `perfmon `
182
182
(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
206
206
def f_vec(x, y):
207
207
return np.cos(x**2 + y**2) / (1 + x**2 + y**2)
208
208
209
- grid = np.linspace(-3, 3, 1000)
210
- x, y = np.meshgrid(grid, grid)
211
-
212
209
np.max(f_vec(x, y)) # Run once to compile
213
210
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) )
217
214
218
215
At least on our machine, the difference in the speed between the
219
216
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
263
260
264
261
np.max(f_vec(x, y)) # Run once to compile
265
262
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) )
269
266
270
- Now our code runs significantly faster than the NumPy version!
267
+ Now our code runs significantly faster than the NumPy version.
271
268
272
269
273
270
0 commit comments