From 485e8ef564889ce81cc0caf222471a3fa323ef12 Mon Sep 17 00:00:00 2001 From: poulami-sau <109125687+poulami-sau@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:46:53 -0400 Subject: [PATCH] added test case in testing/python/approx.py based on test case provided by reporter in issue #12114 --- testing/python/approx.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/testing/python/approx.py b/testing/python/approx.py index 079667bd0..6a58cabff 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -763,6 +763,23 @@ class TestApprox: assert a12 != approx(a21) assert a21 != approx(a12) + def test_numpy_array_implicit_conversion(self): + np = pytest.importorskip("numpy") + + class ImplicitArray: + """Type which is implicitly convertible to a numpy array.""" + + def __init__(self, vals): + self.vals = vals + + def __array__(self, dtype=None, copy=None): + print("called __array__ in ImplicitArray") + return np.array(self.vals) + + vec1 = ImplicitArray([1.0, 2.0, 3.0]) + vec2 = ImplicitArray([1.0, 2.0, 4.0]) + assert vec1 != approx(vec2) + def test_numpy_array_protocol(self): """ array-like objects such as tensorflow's DeviceArray are handled like ndarray.