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

Method test_half_funcs

numpy/core/tests/test_half.py:314–352  ·  view source on GitHub ↗

Test the various ArrFuncs

(self)

Source from the content-addressed store, hash-verified

312 assert_equal(np.nonzero(a[1:] > a[:-1])[0].size, a.size-2)
313
314 def test_half_funcs(self):
315 """Test the various ArrFuncs"""
316
317 # fill
318 assert_equal(np.arange(10, dtype=float16),
319 np.arange(10, dtype=float32))
320
321 # fillwithscalar
322 a = np.zeros((5,), dtype=float16)
323 a.fill(1)
324 assert_equal(a, np.ones((5,), dtype=float16))
325
326 # nonzero and copyswap
327 a = np.array([0, 0, -1, -1/1e20, 0, 2.0**-24, 7.629e-6], dtype=float16)
328 assert_equal(a.nonzero()[0],
329 [2, 5, 6])
330 a = a.byteswap()
331 a = a.view(a.dtype.newbyteorder())
332 assert_equal(a.nonzero()[0],
333 [2, 5, 6])
334
335 # dot
336 a = np.arange(0, 10, 0.5, dtype=float16)
337 b = np.ones((20,), dtype=float16)
338 assert_equal(np.dot(a, b),
339 95)
340
341 # argmax
342 a = np.array([0, -np.inf, -2, 0.5, 12.55, 7.3, 2.1, 12.4], dtype=float16)
343 assert_equal(a.argmax(),
344 4)
345 a = np.array([0, -np.inf, -2, np.inf, 12.55, np.nan, 2.1, 12.4], dtype=float16)
346 assert_equal(a.argmax(),
347 5)
348
349 # getitem
350 a = np.arange(10, dtype=float16)
351 for i in range(10):
352 assert_equal(a.item(i), i)
353
354 def test_spacing_nextafter(self):
355 """Test np.spacing and np.nextafter"""

Callers

nothing calls this directly

Calls 7

assert_equalFunction · 0.90
nonzeroMethod · 0.80
byteswapMethod · 0.80
dotMethod · 0.80
itemMethod · 0.80
viewMethod · 0.45
argmaxMethod · 0.45

Tested by

no test coverage detected