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

Method test_division_int_boundary

numpy/core/tests/test_umath.py:483–539  ·  view source on GitHub ↗
(self, dtype, ex_val)

Source from the content-addressed store, hash-verified

481 )
482 ))
483 def test_division_int_boundary(self, dtype, ex_val):
484 fo = np.iinfo(dtype)
485 neg = -1 if fo.min < 0 else 1
486 # Large enough to test SIMD loops and remainder elements
487 lsize = 512 + 7
488 a, b, divisors = eval(ex_val)
489 a_lst, b_lst = a.tolist(), b.tolist()
490
491 c_div = lambda n, d: (
492 0 if d == 0 else (
493 fo.min if (n and n == fo.min and d == -1) else n//d
494 )
495 )
496 with np.errstate(divide='ignore'):
497 ac = a.copy()
498 ac //= b
499 div_ab = a // b
500 div_lst = [c_div(x, y) for x, y in zip(a_lst, b_lst)]
501
502 msg = "Integer arrays floor division check (//)"
503 assert all(div_ab == div_lst), msg
504 msg_eq = "Integer arrays floor division check (//=)"
505 assert all(ac == div_lst), msg_eq
506
507 for divisor in divisors:
508 ac = a.copy()
509 with np.errstate(divide='ignore', over='ignore'):
510 div_a = a // divisor
511 ac //= divisor
512 div_lst = [c_div(i, divisor) for i in a_lst]
513
514 assert all(div_a == div_lst), msg
515 assert all(ac == div_lst), msg_eq
516
517 with np.errstate(divide='raise', over='raise'):
518 if 0 in b:
519 # Verify overflow case
520 with pytest.raises(FloatingPointError,
521 match="divide by zero encountered in floor_divide"):
522 a // b
523 else:
524 a // b
525 if fo.min and fo.min in a:
526 with pytest.raises(FloatingPointError,
527 match='overflow encountered in floor_divide'):
528 a // -1
529 elif fo.min:
530 a // -1
531 with pytest.raises(FloatingPointError,
532 match="divide by zero encountered in floor_divide"):
533 a // 0
534 with pytest.raises(FloatingPointError,
535 match="divide by zero encountered in floor_divide"):
536 ac = a.copy()
537 ac //= 0
538
539 np.array([], dtype=dtype) // 0
540

Callers

nothing calls this directly

Calls 3

allFunction · 0.50
tolistMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected