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

Method test_division_int_reduce

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

Source from the content-addressed store, hash-verified

548 )
549 ))
550 def test_division_int_reduce(self, dtype, ex_val):
551 fo = np.iinfo(dtype)
552 a = eval(ex_val)
553 lst = a.tolist()
554 c_div = lambda n, d: (
555 0 if d == 0 or (n and n == fo.min and d == -1) else n//d
556 )
557
558 with np.errstate(divide='ignore'):
559 div_a = np.floor_divide.reduce(a)
560 div_lst = reduce(c_div, lst)
561 msg = "Reduce floor integer division check"
562 assert div_a == div_lst, msg
563
564 with np.errstate(divide='raise', over='raise'):
565 with pytest.raises(FloatingPointError,
566 match="divide by zero encountered in reduce"):
567 np.floor_divide.reduce(np.arange(-100, 100).astype(dtype))
568 if fo.min:
569 with pytest.raises(FloatingPointError,
570 match='overflow encountered in reduce'):
571 np.floor_divide.reduce(
572 np.array([fo.min, 1, -1], dtype=dtype)
573 )
574
575 @pytest.mark.parametrize(
576 "dividend,divisor,quotient",

Callers

nothing calls this directly

Calls 3

astypeMethod · 0.80
tolistMethod · 0.45
reduceMethod · 0.45

Tested by

no test coverage detected