pybamm-team / PyBaMM

Fast and flexible physics-based battery models in Python
https://www.pybamm.org/
BSD 3-Clause "New" or "Revised" License
1.08k stars 534 forks source link

Use `numpy.testing.assert_allclose` for more consistent floating-point comparisons #4488

Open agriyakhetarpal opened 2 days ago

agriyakhetarpal commented 2 days ago

Currently, we use np.testing.assert_array_almost_equal in 404 places across 41 files, but the NumPy authors no longer recommend it. We should switch to the recommended np.testing.assert_allclose testing method where we can (which can be in one PR or multiple PRs), across all our tests.

Please note that there are a few differences in the number of arguments both functions take and in the default tolerance(s) set for them, so it's not a quick swap and some failures could be expected – but it should still be easy for someone to take it up in parts.

Saransh-cpp commented 1 day ago

Also, all the instances of assert all(numpy_array == numpy_array)/assert np.allclose(numpy_array == numpy_array) (if we have any) should be replaced with numpy.testing calls.