From 69c55465a2e2c785ac999e746ce8a0a7c4993e01 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Wed, 13 May 2026 16:50:03 +0530 Subject: [PATCH] Adding verbose and equal_nan options Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/_lib/_testing.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/array_api_extra/_lib/_testing.py b/src/array_api_extra/_lib/_testing.py index 30e2f1ef..049f4afa 100644 --- a/src/array_api_extra/_lib/_testing.py +++ b/src/array_api_extra/_lib/_testing.py @@ -139,6 +139,7 @@ def xp_assert_equal( desired: Array, *, err_msg: str = "", + verbose: bool = True, check_dtype: bool = True, check_shape: bool = True, check_scalar: bool = False, @@ -154,6 +155,8 @@ def xp_assert_equal( The expected array (typically hardcoded). err_msg : str, optional Error message to display on failure. + verbose: bool, default: True + Whether to include the conflicting arrays in the error message on failure. check_dtype, check_shape : bool, default: True Whether to check agreement between actual and desired dtypes and shapes check_scalar : bool, default: False @@ -170,7 +173,9 @@ def xp_assert_equal( return actual_np = as_numpy_array(actual, xp=xp) desired_np = as_numpy_array(desired, xp=xp) - np.testing.assert_array_equal(actual_np, desired_np, err_msg=err_msg) + np.testing.assert_array_equal( + actual_np, desired_np, err_msg=err_msg, verbose=verbose + ) def xp_assert_less( @@ -178,6 +183,7 @@ def xp_assert_less( y: Array, *, err_msg: str = "", + verbose: bool = True, check_dtype: bool = True, check_shape: bool = True, check_scalar: bool = False, @@ -191,6 +197,8 @@ def xp_assert_less( The arrays to compare according to ``x < y`` (elementwise). err_msg : str, optional Error message to display on failure. + verbose: bool, default: True + Whether to include the conflicting arrays in the error message on failure. check_dtype, check_shape : bool, default: True Whether to check agreement between actual and desired dtypes and shapes check_scalar : bool, default: False @@ -207,7 +215,7 @@ def xp_assert_less( return x_np = as_numpy_array(x, xp=xp) y_np = as_numpy_array(y, xp=xp) - np.testing.assert_array_less(x_np, y_np, err_msg=err_msg) + np.testing.assert_array_less(x_np, y_np, err_msg=err_msg, verbose=verbose) def xp_assert_close( @@ -216,7 +224,9 @@ def xp_assert_close( *, rtol: float | None = None, atol: float = 0, + equal_nan: bool = True, err_msg: str = "", + verbose: bool = True, check_dtype: bool = True, check_shape: bool = True, check_scalar: bool = False, @@ -234,8 +244,12 @@ def xp_assert_close( Relative tolerance. Default: dtype-dependent. atol : float, optional Absolute tolerance. Default: 0. + equal_nan : bool, default: True + Whether to consider NaNs in corresponding locations as equal. err_msg : str, optional Error message to display on failure. + verbose: bool, default: True + Whether to include the conflicting arrays in the error message on failure. check_dtype, check_shape : bool, default: True Whether to check agreement between actual and desired dtypes and shapes check_scalar : bool, default: False @@ -272,7 +286,9 @@ def xp_assert_close( desired_np, rtol=rtol, # pyright: ignore[reportArgumentType] atol=atol, + equal_nan=equal_nan, err_msg=err_msg, + verbose=verbose, )