summaryrefslogtreecommitdiff
path: root/numpy/random
diff options
context:
space:
mode:
authorKevin Sheppard <kevin.k.sheppard@gmail.com>2018-12-14 15:47:25 +0000
committerKevin Sheppard <kevin.k.sheppard@gmail.com>2018-12-14 15:47:25 +0000
commitf879e4fafd5dec5a68d9ff060c250db0a9aa0c5c (patch)
treef50710ade7e6e32b1470c6e46236cf2fcf560894 /numpy/random
parent2f231b3231b5c9ae5d95b23a27d141091706df0c (diff)
downloadnumpy-f879e4fafd5dec5a68d9ff060c250db0a9aa0c5c.tar.gz
ENH: Cast covariance to double in random mvnormal
Cast the covariance in the multivariate normal to double so that the interpretation of tol is cleaner. closes #10839
Diffstat (limited to 'numpy/random')
-rw-r--r--numpy/random/mtrand/mtrand.pyx3
-rw-r--r--numpy/random/tests/test_random.py6
2 files changed, 9 insertions, 0 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index 059a39e55..f49d03c42 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -4408,6 +4408,7 @@ cdef class RandomState:
Behavior when the covariance matrix is not positive semidefinite.
tol : float, optional
Tolerance when checking the singular values in covariance matrix.
+ cov is cast to double before the check.
Returns
-------
@@ -4519,6 +4520,8 @@ cdef class RandomState:
# not zero. We continue to use the SVD rather than Cholesky in
# order to preserve current outputs.
+ # GH10839, ensure double to make tol meaningful
+ cov = cov.astype(np.double)
(u, s, v) = svd(cov)
if check_valid != 'ignore':
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index d0bb92a73..d35d32886 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -712,6 +712,12 @@ class TestRandomDist(object):
assert_raises(ValueError, np.random.multivariate_normal, mean, cov,
check_valid='raise')
+ cov = np.array([[1, 0.1],[0.1, 1]], dtype=np.float32)
+ with suppress_warnings() as sup:
+ np.random.multivariate_normal(mean, cov)
+ w = sup.record(RuntimeWarning)
+ assert len(w) == 0
+
def test_negative_binomial(self):
np.random.seed(self.seed)
actual = np.random.negative_binomial(n=100, p=.12345, size=(3, 2))