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

Method check_count_nonzero

numpy/core/tests/test_multiarray.py:1667–1680  ·  view source on GitHub ↗
(self, power, length)

Source from the content-addressed store, hash-verified

1665 assert_equal(d[::-2].sum(), d[::-2].size)
1666
1667 def check_count_nonzero(self, power, length):
1668 powers = [2 ** i for i in range(length)]
1669 for i in range(2**power):
1670 l = [(i & x) != 0 for x in powers]
1671 a = np.array(l, dtype=bool)
1672 c = builtins.sum(l)
1673 assert_equal(np.count_nonzero(a), c)
1674 av = a.view(np.uint8)
1675 av *= 3
1676 assert_equal(np.count_nonzero(a), c)
1677 av *= 4
1678 assert_equal(np.count_nonzero(a), c)
1679 av[av != 0] = 0xFF
1680 assert_equal(np.count_nonzero(a), c)
1681
1682 def test_count_nonzero(self):
1683 # check all 12 bit combinations in a length 17 array

Callers 2

test_count_nonzeroMethod · 0.95

Calls 3

assert_equalFunction · 0.90
sumMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected