MCPcopy Index your code
hub / github.com/numpy/numpy / test_half_ordering

Method test_half_ordering

numpy/_core/tests/test_half.py:311–333  ·  view source on GitHub ↗

Make sure comparisons are working right

(self)

Source from the content-addressed store, hash-verified

309 f"{finite_f64[bad_index]:g} != {a_manual[bad_index]:g}")
310
311 def test_half_ordering(self):
312 """Make sure comparisons are working right"""
313 nonan_f16, _, _ = self._create_arrays_nonan()
314
315 # All non-NaN float16 values in reverse order
316 a = nonan_f16[::-1].copy()
317
318 # 32-bit float copy
319 b = np.array(a, dtype=float32)
320
321 # Should sort the same
322 a.sort()
323 b.sort()
324 assert_equal(a, b)
325
326 # Comparisons should work
327 assert_((a[:-1] <= a[1:]).all())
328 assert_(not (a[:-1] > a[1:]).any())
329 assert_((a[1:] >= a[:-1]).all())
330 assert_(not (a[1:] < a[:-1]).any())
331 # All != except for +/-0
332 assert_equal(np.nonzero(a[:-1] < a[1:])[0].size, a.size - 2)
333 assert_equal(np.nonzero(a[1:] > a[:-1])[0].size, a.size - 2)
334
335 def test_half_funcs(self):
336 """Test the various ArrFuncs"""

Callers

nothing calls this directly

Calls 8

_create_arrays_nonanMethod · 0.95
assert_equalFunction · 0.90
assert_Function · 0.90
nonzeroMethod · 0.80
copyMethod · 0.45
sortMethod · 0.45
allMethod · 0.45
anyMethod · 0.45

Tested by

no test coverage detected