def test_product(dtype, nelem): if np.dtype(dtype).kind == "i": data = np.ones(nelem, dtype=dtype) # Set at most 30 items to [0..2) to keep the value within 2^32 for _ in range(30): data[random.randrange(nelem)] = random.random() * 2 else: data = gen_rand(dtype, nelem) sr = Series(data) got = sr.product() expect = np.product(data) significant = 4 if dtype == np.float32 else 6 np.testing.assert_approx_equal(expect, got, significant=significant)
def test_product(dtype, nelem): np.random.seed(0) dtype = np.dtype(dtype).type if np.dtype(dtype).kind in {"u", "i"}: data = np.ones(nelem, dtype=dtype) # Set at most 30 items to [0..2) to keep the value within 2^32 for _ in range(30): data[np.random.randint(low=0, high=nelem, size=1)] = (np.random.uniform() * 2) else: data = gen_rand(dtype, nelem) sr = Series(data) got = sr.product() expect = np.product(data) significant = 4 if dtype == np.float32 else 6 np.testing.assert_approx_equal(expect, got, significant=significant)