summaryrefslogtreecommitdiff
path: root/numpy/random/tests/test_regression.py
diff options
context:
space:
mode:
authoralex <argriffi@ncsu.edu>2015-07-29 18:48:47 -0400
committeralex <argriffi@ncsu.edu>2015-07-29 18:48:47 -0400
commitb6d0263239926e8b14ebc26a0d7b9469fa7866d4 (patch)
treec1c6e40d7780fd6652797dcd3ad759be0b8e838f /numpy/random/tests/test_regression.py
parenta92c4a108bd9b2b14f306534ad3105ed76485572 (diff)
downloadnumpy-b6d0263239926e8b14ebc26a0d7b9469fa7866d4.tar.gz
MAINT: adjust tolerance for validating the sum of probs in random.choice
Diffstat (limited to 'numpy/random/tests/test_regression.py')
-rw-r--r--numpy/random/tests/test_regression.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/numpy/random/tests/test_regression.py b/numpy/random/tests/test_regression.py
index 52be0d4d5..528ef7839 100644
--- a/numpy/random/tests/test_regression.py
+++ b/numpy/random/tests/test_regression.py
@@ -2,7 +2,7 @@ from __future__ import division, absolute_import, print_function
import sys
from numpy.testing import (TestCase, run_module_suite, assert_,
- assert_array_equal)
+ assert_array_equal, assert_raises)
from numpy import random
from numpy.compat import long
import numpy as np
@@ -100,6 +100,18 @@ class TestRegression(TestCase):
x = np.random.beta(0.0001, 0.0001, size=100)
assert_(not np.any(np.isnan(x)), 'Nans in np.random.beta')
+ def test_choice_sum_of_probs_tolerance(self):
+ # The sum of probs should be 1.0 with some tolerance.
+ # For low precision dtypes the tolerance was too tight.
+ # See numpy github issue 6123.
+ np.random.seed(1234)
+ a = [1, 2, 3]
+ counts = [4, 4, 2]
+ for dt in np.float16, np.float32, np.float64:
+ probs = np.array(counts, dtype=dt) / sum(counts)
+ c = np.random.choice(a, p=probs)
+ assert_(c in a)
+ assert_raises(ValueError, np.random.choice, a, p=probs*0.9)
if __name__ == "__main__":
run_module_suite()