diff options
author | alex <argriffi@ncsu.edu> | 2015-07-29 18:48:47 -0400 |
---|---|---|
committer | alex <argriffi@ncsu.edu> | 2015-07-29 18:48:47 -0400 |
commit | b6d0263239926e8b14ebc26a0d7b9469fa7866d4 (patch) | |
tree | c1c6e40d7780fd6652797dcd3ad759be0b8e838f /numpy/random/tests/test_regression.py | |
parent | a92c4a108bd9b2b14f306534ad3105ed76485572 (diff) | |
download | numpy-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.py | 14 |
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() |