diff --git a/docs/reference/toctree.txt b/docs/reference/toctree.txt index 126e0a2b9c..4b6ae1154d 100644 --- a/docs/reference/toctree.txt +++ b/docs/reference/toctree.txt @@ -299,11 +299,12 @@ generated/ak.backend .. toctree:: - :caption: Approximation + :caption: Approximation and comparison generated/ak.round generated/ak.isclose generated/ak.almost_equal + generated/ak.array_equal .. toctree:: :caption: NumPy compatibility diff --git a/src/awkward/operations/ak_almost_equal.py b/src/awkward/operations/ak_almost_equal.py index 78461de65c..66f67e4d8a 100644 --- a/src/awkward/operations/ak_almost_equal.py +++ b/src/awkward/operations/ak_almost_equal.py @@ -2,10 +2,11 @@ from __future__ import annotations -from awkward._backends.dispatch import backend_of_obj +from awkward._backends.dispatch import backend_of from awkward._backends.numpy import NumpyBackend from awkward._behavior import behavior_of, get_array_class, get_record_class from awkward._dispatch import high_level_function +from awkward._layout import ensure_same_backend from awkward._nplikes.numpy_like import NumpyMetadata from awkward._parameters import parameters_are_equal from awkward.operations.ak_to_layout import to_layout @@ -82,14 +83,13 @@ def _impl( left_behavior = behavior_of(left) right_behavior = behavior_of(right) - left_backend = backend_of_obj(left, default=cpu) - right_backend = backend_of_obj(right, default=cpu) - if left_backend is not right_backend: - return False - backend = left_backend - - left_layout = to_layout(left, allow_record=False).to_packed() - right_layout = to_layout(right, allow_record=False).to_packed() + layouts = ensure_same_backend( + to_layout(left, allow_record=False), + to_layout(right, allow_record=False), + ) + left_layout = layouts[0].to_packed() + right_layout = layouts[1].to_packed() + backend = backend_of(left_layout) if not backend.nplike.known_data: raise NotImplementedError( diff --git a/src/awkward/operations/ak_array_equal.py b/src/awkward/operations/ak_array_equal.py index 2a7221baab..398db6b2a6 100644 --- a/src/awkward/operations/ak_array_equal.py +++ b/src/awkward/operations/ak_array_equal.py @@ -8,6 +8,7 @@ __all__ = ("array_equal",) +@ak._connect.numpy.implements("array_equal") @high_level_function() def array_equal( a1, diff --git a/tests/test_1105_ak_aray_equal.py b/tests/test_1105_ak_aray_equal.py index 519d0039c5..7512f50316 100644 --- a/tests/test_1105_ak_aray_equal.py +++ b/tests/test_1105_ak_aray_equal.py @@ -88,3 +88,10 @@ def test_array_equal_with_params(): ) assert not ak.array_equal(a1, a2) assert ak.array_equal(a1, a2, check_parameters=False) + + +def test_array_equal_numpy_override(): + assert np.array_equal( + ak.Array([[1, 2], [], [3, 4, 5]]), + ak.Array([[1, 2], [], [3, 4, 5]]), + ) diff --git a/tests/test_2305_nep_18_lazy_conversion.py b/tests/test_2305_nep_18_lazy_conversion.py index 8ce4c88763..a3c9cd71d0 100644 --- a/tests/test_2305_nep_18_lazy_conversion.py +++ b/tests/test_2305_nep_18_lazy_conversion.py @@ -11,7 +11,10 @@ def test_binary(): ak_array = ak.Array(np.arange(10, dtype="