xp_assert_equal¶
- xp_assert_equal(actual, desired, *, check_namespace=True, check_dtype=True, check_shape=True, check_0d=True, err_msg='', xp: ModuleType | None = None)[source][source]¶
Assert that two arrays are equal.
- Parameters:
actual (
array_like) – The array to test.desired (
array_like) – The expected array.check_namespace (
bool, optional) – If True, check that the arrays have the same namespace.check_dtype (
bool, optional) – If True, check that the arrays have the same dtype.check_shape (
bool, optional) – If True, check that the arrays have the same shape.check_0d (
bool, optional) – If True, check that the arrays have the same dimensionality.err_msg (
str, optional) – The error message to be printed in case of failure.xp (
module, optional) –- The array API namespace to use. If not provided, the namespace is
inferred from the arrays.
- Returns:
If the arrays are equal, otherwise raises an AssertionError.
- Return type:
Notes
- This function is a wrapper around the testing functions of different array
- libraries, providing a consistent interface for equality testing across
different backends.
Examples
>>> import numpy as np >>> a = np.array([1, 2, 3]) >>> b = np.array([1, 2, 3]) >>> xp_assert_equal(a, b) # No error raised >>> c = np.array([1, 2, 4]) >>> xp_assert_equal(a, c) Traceback (most recent call last): ... AssertionError: Arrays are not equal