Skip to content

Commit 018e9d3

Browse files
committed
testing: switch to numpy.testing for array and value checks in tests
1 parent 171969e commit 018e9d3

66 files changed

Lines changed: 354 additions & 351 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmarks/user/benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def test(problem, **kwargs):
402402
last_res = res
403403
else:
404404
for i in range(len(res)):
405-
assert np.isclose(res[i], last_res[i])
405+
np.testing.assert_allclose(res[i], last_res[i])
406406

407407

408408
if __name__ == "__main__":

examples/cfd/01_convection.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
"\n",
323323
"# Some small sanity checks for the testing framework\n",
324324
"assert (u.data[0, 45:55, 45:55] > 1.8).all()\n",
325-
"assert np.allclose(u.data[0], u_ref, rtol=3.e-2)"
325+
"np.testing.assert_allclose(u.data[0], u_ref, rtol=3.e-2)"
326326
]
327327
},
328328
{
@@ -390,7 +390,7 @@
390390
"\n",
391391
"# Some small sanity checks for the testing framework\n",
392392
"assert (u.data[0, 45:55, 45:55] > 1.8).all()\n",
393-
"assert np.allclose(u.data[0], u_ref, rtol=3.e-2)"
393+
"np.testing.assert_allclose(u.data[0], u_ref, rtol=3.e-2)"
394394
]
395395
},
396396
{

examples/cfd/01_convection_revisited.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@
305305
"\n",
306306
"# Some small sanity checks for the testing framework\n",
307307
"assert (u.data[0, 45:55, 45:55] > 1.8).all()\n",
308-
"assert np.allclose(u.data[0], u_ref, rtol=3.e-2)"
308+
"np.testing.assert_allclose(u.data[0], u_ref, rtol=3.e-2)"
309309
]
310310
},
311311
{
@@ -366,7 +366,7 @@
366366
"\n",
367367
"# Some small sanity checks for the testing framework\n",
368368
"assert (u.data[0, 45:55, 45:55] > 1.8).all()\n",
369-
"assert np.allclose(u.data[0], u_ref, rtol=3.e-2)"
369+
"np.testing.assert_allclose(u.data[0], u_ref, rtol=3.e-2)"
370370
]
371371
},
372372
{

examples/cfd/02_convection_nonlinear.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@
467467
"outputs": [],
468468
"source": [
469469
"from devito import norm\n",
470-
"assert np.isclose(norm(u), norm(U[0]), rtol=1e-2, atol=0)"
470+
"np.testing.assert_allclose(norm(u), norm(U[0]), rtol=1e-2, atol=0)"
471471
]
472472
}
473473
],

examples/cfd/09_Darcy_flow_equation.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@
419419
"metadata": {},
420420
"outputs": [],
421421
"source": [
422-
"assert np.isclose(LA.norm(output1), 1.0335084, atol=1e-3, rtol=0)\n",
423-
"assert np.isclose(LA.norm(output2), 1.3038709, atol=1e-3, rtol=0)\n",
424-
"assert np.isclose(LA.norm(output3), 1.3940924, atol=1e-3, rtol=0)"
422+
"np.testing.assert_allclose(LA.norm(output1), 1.0335084, atol=1e-3, rtol=0)\n",
423+
"np.testing.assert_allclose(LA.norm(output2), 1.3038709, atol=1e-3, rtol=0)\n",
424+
"np.testing.assert_allclose(LA.norm(output3), 1.3940924, atol=1e-3, rtol=0)"
425425
]
426426
},
427427
{

examples/seismic/abc_methods/01_introduction.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@
11031103
"metadata": {},
11041104
"outputs": [],
11051105
"source": [
1106-
"assert np.isclose(np.linalg.norm(rec.data), 990, rtol=1)"
1106+
"np.testing.assert_allclose(np.linalg.norm(rec.data), 990, rtol=1)"
11071107
]
11081108
},
11091109
{

examples/seismic/abc_methods/02_damping.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@
12321232
"metadata": {},
12331233
"outputs": [],
12341234
"source": [
1235-
"assert np.isclose(np.linalg.norm(rec.data), 990, rtol=1)"
1235+
"np.testing.assert_allclose(np.linalg.norm(rec.data), 990, rtol=1)"
12361236
]
12371237
},
12381238
{

examples/seismic/abc_methods/03_pml.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@
14101410
"metadata": {},
14111411
"outputs": [],
14121412
"source": [
1413-
"assert np.isclose(np.linalg.norm(rec.data), 990, rtol=1)"
1413+
"np.testing.assert_allclose(np.linalg.norm(rec.data), 990, rtol=1)"
14141414
]
14151415
},
14161416
{

examples/seismic/abc_methods/04_habc.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@
16411641
"metadata": {},
16421642
"outputs": [],
16431643
"source": [
1644-
"assert np.isclose(np.linalg.norm(rec.data), 990, rtol=1)"
1644+
"np.testing.assert_allclose(np.linalg.norm(rec.data), 990, rtol=1)"
16451645
]
16461646
},
16471647
{

examples/seismic/acoustic/accuracy.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@
552552
"# NBVAL_IGNORE_OUTPUT\n",
553553
"pf = np.polyfit(np.log([t for t in dt]), np.log(error_time), deg=1)\n",
554554
"print(f\"Convergence rate in time is: {pf[0]:.4f}\")\n",
555-
"assert np.isclose(pf[0], 1.9, atol=0, rtol=.1)"
555+
"np.testing.assert_allclose(pf[0], 1.9, atol=0, rtol=.1)"
556556
]
557557
},
558558
{
@@ -742,7 +742,7 @@
742742
" pf = np.polyfit(np.log([sc for sc in dx][1:]), np.log(errorl2[i, 1:]), deg=1)[0]\n",
743743
" print(f\"Convergence rate for order {orders[i]} is {pf}\")\n",
744744
" if i < 4:\n",
745-
" assert np.isclose(pf, orders[i], atol=0, rtol=.2)"
745+
" np.testing.assert_allclose(pf, orders[i], atol=0, rtol=.2)"
746746
]
747747
}
748748
],

0 commit comments

Comments
 (0)