rougier / from-python-to-numpy

An open-access book on numpy vectorization techniques, Nicolas P. Rougier, 2017
http://www.labri.fr/perso/nrougier/from-python-to-numpy
Other
2.06k stars 340 forks source link

`smoke` example fails on numpy 1.24.2 #110

Closed ev-br closed 1 year ago

ev-br commented 1 year ago

Running the smoke simulation (smoke_1.py) under numpy 1.24.2 fails to apply binary subtraction operator on boolean arrays. A quick-and-dirty fix to restore the simulation:

$ git diff HEAD^
diff --git a/e2e/smoke/smoke_1.py b/e2e/smoke/smoke_1.py
index f858fde..5cca8eb 100644
--- a/e2e/smoke/smoke_1.py
+++ b/e2e/smoke/smoke_1.py
@@ -40,7 +40,7 @@ def initialization():
         D = np.fromfunction(distance, shape)
         return np.where(D <= radius, True, False)

-    D = disc(radius=32) - disc(radius=16)
+    D = disc(radius=32) ^ disc(radius=16)
     dens[...] = D*source/10
     u[:, :] = force * 0.1 * np.random.uniform(-1, 1, u.shape)
     v[:, :] = force * 0.1 * np.random.uniform(-1, 1, u.shape)

I'll take a chance to say huge thanks for the book. I keep recommending it to students.

ev-br commented 1 year ago

Also in mandelbrot.py: https://github.com/rougier/from-python-to-numpy/blob/master/code/mandelbrot.py#L34 uses np.negative

rougier commented 1 year ago

Thanks! Can you make a PR?

ev-br commented 1 year ago

done: https://github.com/rougier/from-python-to-numpy/pull/111