Test the various ArrFuncs
(self)
| 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""" |
| 337 | |
| 338 | # fill |
| 339 | assert_equal(np.arange(10, dtype=float16), |
| 340 | np.arange(10, dtype=float32)) |
| 341 | |
| 342 | # fillwithscalar |
| 343 | a = np.zeros((5,), dtype=float16) |
| 344 | a.fill(1) |
| 345 | assert_equal(a, np.ones((5,), dtype=float16)) |
| 346 | |
| 347 | # nonzero and copyswap |
| 348 | a = np.array([0, 0, -1, -1 / 1e20, 0, 2.0**-24, 7.629e-6], dtype=float16) |
| 349 | assert_equal(a.nonzero()[0], |
| 350 | [2, 5, 6]) |
| 351 | a = a.byteswap() |
| 352 | a = a.view(a.dtype.newbyteorder()) |
| 353 | assert_equal(a.nonzero()[0], |
| 354 | [2, 5, 6]) |
| 355 | |
| 356 | # dot |
| 357 | a = np.arange(0, 10, 0.5, dtype=float16) |
| 358 | b = np.ones((20,), dtype=float16) |
| 359 | assert_equal(np.dot(a, b), |
| 360 | 95) |
| 361 | |
| 362 | # argmax |
| 363 | a = np.array([0, -np.inf, -2, 0.5, 12.55, 7.3, 2.1, 12.4], dtype=float16) |
| 364 | assert_equal(a.argmax(), |
| 365 | 4) |
| 366 | a = np.array([0, -np.inf, -2, np.inf, 12.55, np.nan, 2.1, 12.4], dtype=float16) |
| 367 | assert_equal(a.argmax(), |
| 368 | 5) |
| 369 | |
| 370 | # getitem |
| 371 | a = np.arange(10, dtype=float16) |
| 372 | for i in range(10): |
| 373 | assert_equal(a.item(i), i) |
| 374 | |
| 375 | def test_spacing_nextafter(self): |
| 376 | """Test np.spacing and np.nextafter""" |