MCPcopy
hub / github.com/pytorch/pytorch / assert_equal

Function assert_equal

torch/_numpy/testing/utils.py:132–282  ·  view source on GitHub ↗

Raises an AssertionError if two objects are not equal. Given two objects (scalars, lists, tuples, dictionaries or numpy arrays), check that all elements of these objects are equal. An exception is raised at the first conflicting values. When one of `actual` and `desired` is a

(actual, desired, err_msg="", verbose=True)

Source from the content-addressed store, hash-verified

130
131
132def assert_equal(actual, desired, err_msg="", verbose=True):
133 """
134 Raises an AssertionError if two objects are not equal.
135
136 Given two objects (scalars, lists, tuples, dictionaries or numpy arrays),
137 check that all elements of these objects are equal. An exception is raised
138 at the first conflicting values.
139
140 When one of `actual` and `desired` is a scalar and the other is array_like,
141 the function checks that each element of the array_like object is equal to
142 the scalar.
143
144 This function handles NaN comparisons as if NaN was a "normal" number.
145 That is, AssertionError is not raised if both objects have NaNs in the same
146 positions. This is in contrast to the IEEE standard on NaNs, which says
147 that NaN compared to anything must return False.
148
149 Parameters
150 ----------
151 actual : array_like
152 The object to check.
153 desired : array_like
154 The expected object.
155 err_msg : str, optional
156 The error message to be printed in case of failure.
157 verbose : bool, optional
158 If True, the conflicting values are appended to the error message.
159
160 Raises
161 ------
162 AssertionError
163 If actual and desired are not equal.
164
165 Examples
166 --------
167 >>> np.testing.assert_equal([4,5], [4,6])
168 Traceback (most recent call last):
169 ...
170 AssertionError:
171 Items are not equal:
172 item=1
173 ACTUAL: 5
174 DESIRED: 6
175
176 The following comparison does not raise an exception. There are NaNs
177 in the inputs, but they are in the same positions.
178
179 >>> np.testing.assert_equal(np.array([1.0, 2.0, np.nan]), [1, 2, np.nan])
180
181 """
182 __tracebackhide__ = True # Hide traceback for py.test
183
184 num_nones = sum([actual is None, desired is None])
185 if num_nones == 1:
186 raise AssertionError(f"Not equal: {actual} != {desired}")
187 elif num_nones == 2:
188 return True
189 # else, carry on

Callers 15

test_vector_vs_scalarMethod · 0.90
test_basicMethod · 0.90
test_other_scalarMethod · 0.90
test_other_arrayMethod · 0.90
test_basicMethod · 0.90
test_divmod_outMethod · 0.90
test_divmod_no_outMethod · 0.90
test_arrays_in_listsMethod · 0.90

Calls 12

iscomplexobjFunction · 0.90
realFunction · 0.90
imagFunction · 0.90
isscalarFunction · 0.90
isinstanceFunction · 0.85
assert_array_equalFunction · 0.85
build_err_msgFunction · 0.85
gisnanFunction · 0.85
signbitFunction · 0.85
sumFunction · 0.50
rangeFunction · 0.50
keysMethod · 0.45

Tested by 15

test_vector_vs_scalarMethod · 0.72
test_basicMethod · 0.72
test_other_scalarMethod · 0.72
test_other_arrayMethod · 0.72
test_basicMethod · 0.72
test_divmod_outMethod · 0.72
test_divmod_no_outMethod · 0.72
test_arrays_in_listsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…