MCPcopy Create free account
hub / github.com/cupy/cupy / assert_array_equal

Function assert_array_equal

cupy/testing/_array.py:102–147  ·  view source on GitHub ↗

Raises an AssertionError if two array_like objects are not equal. Args: x(numpy.ndarray or cupy.ndarray): The actual object to check. y(numpy.ndarray or cupy.ndarray): The desired, expected object. strides_check(bool): If ``True``, consistency of strides is also

(
        actual, desired, err_msg='', verbose=True, *,
        strict=False, strides_check=False
)

Source from the content-addressed store, hash-verified

100
101
102def assert_array_equal(
103 actual, desired, err_msg='', verbose=True, *,
104 strict=False, strides_check=False
105):
106 """Raises an AssertionError if two array_like objects are not equal.
107
108 Args:
109 x(numpy.ndarray or cupy.ndarray): The actual object to check.
110 y(numpy.ndarray or cupy.ndarray): The desired, expected object.
111 strides_check(bool): If ``True``, consistency of strides is also
112 checked.
113 err_msg(str): The error message to be printed in case of failure.
114 verbose(bool): If ``True``, the conflicting values
115 are appended to the error message.
116 strict(bool): If ``True``, raise an AssertionError when either
117 the shape or the data type of the array_like objects does not
118 match. Requires NumPy version 1.24 or above.
119
120 .. seealso:: :func:`numpy.testing.assert_array_equal`
121 """
122 if numpy.lib.NumpyVersion(numpy.__version__) >= '1.24.0':
123 numpy.testing.assert_array_equal(
124 cupy.asnumpy(actual), cupy.asnumpy(desired), err_msg=err_msg,
125 verbose=verbose, strict=strict,
126 )
127 else:
128 if strict:
129 warnings.warn(
130 '`cupy.testing.assert_allclose` does not support `strict` '
131 'option with NumPy v1.',
132 RuntimeWarning
133 )
134 numpy.testing.assert_array_equal(
135 cupy.asnumpy(actual), cupy.asnumpy(desired), err_msg=err_msg,
136 verbose=verbose,
137 )
138
139 if strides_check:
140 if actual.strides != desired.strides:
141 msg = ['Strides are not equal:']
142 if err_msg:
143 msg = [msg[0] + ' ' + err_msg]
144 if verbose:
145 msg.append(' x: {}'.format(actual.strides))
146 msg.append(' y: {}'.format(desired.strides))
147 raise AssertionError('\n'.join(msg))
148
149
150def assert_array_list_equal(xlist, ylist, err_msg='', verbose=True):

Callers 13

test_nan_x_1dMethod · 0.90
test_nan_x_2dMethod · 0.90
test_nonscalar_valuesMethod · 0.90
test_xi_ndMethod · 0.90
test_xi_broadcastMethod · 0.90
test_nonscalar_valuesMethod · 0.90
check_polyderFunction · 0.90
test_log1p_realMethod · 0.90
test_x_zeroMethod · 0.90

Calls 1

joinMethod · 0.80

Tested by 13

test_nan_x_1dMethod · 0.72
test_nan_x_2dMethod · 0.72
test_nonscalar_valuesMethod · 0.72
test_xi_ndMethod · 0.72
test_xi_broadcastMethod · 0.72
test_nonscalar_valuesMethod · 0.72
check_polyderFunction · 0.72
test_log1p_realMethod · 0.72
test_x_zeroMethod · 0.72