MCPcopy Create free account
hub / github.com/numpy/numpy / test_comparison_functions

Method test_comparison_functions

numpy/core/tests/test_umath.py:280–312  ·  view source on GitHub ↗
(self, dtype, py_comp, np_comp)

Source from the content-addressed store, hash-verified

278 (operator.ne, np.not_equal)
279 ])
280 def test_comparison_functions(self, dtype, py_comp, np_comp):
281 # Initialize input arrays
282 if dtype == np.bool_:
283 a = np.random.choice(a=[False, True], size=1000)
284 b = np.random.choice(a=[False, True], size=1000)
285 scalar = True
286 else:
287 a = np.random.randint(low=1, high=10, size=1000).astype(dtype)
288 b = np.random.randint(low=1, high=10, size=1000).astype(dtype)
289 scalar = 5
290 np_scalar = np.dtype(dtype).type(scalar)
291 a_lst = a.tolist()
292 b_lst = b.tolist()
293
294 # (Binary) Comparison (x1=array, x2=array)
295 comp_b = np_comp(a, b).view(np.uint8)
296 comp_b_list = [int(py_comp(x, y)) for x, y in zip(a_lst, b_lst)]
297
298 # (Scalar1) Comparison (x1=scalar, x2=array)
299 comp_s1 = np_comp(np_scalar, b).view(np.uint8)
300 comp_s1_list = [int(py_comp(scalar, x)) for x in b_lst]
301
302 # (Scalar2) Comparison (x1=array, x2=scalar)
303 comp_s2 = np_comp(a, np_scalar).view(np.uint8)
304 comp_s2_list = [int(py_comp(x, scalar)) for x in a_lst]
305
306 # Sequence: Binary, Scalar1 and Scalar2
307 assert_(comp_b.tolist() == comp_b_list,
308 f"Failed comparison ({py_comp.__name__})")
309 assert_(comp_s1.tolist() == comp_s1_list,
310 f"Failed comparison ({py_comp.__name__})")
311 assert_(comp_s2.tolist() == comp_s2_list,
312 f"Failed comparison ({py_comp.__name__})")
313
314 def test_ignore_object_identity_in_equal(self):
315 # Check comparing identical objects whose comparison

Callers

nothing calls this directly

Calls 5

assert_Function · 0.90
astypeMethod · 0.80
dtypeMethod · 0.45
tolistMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected