|
3 | 3 | import numpy as np
|
4 | 4 | from numpy.testing import (
|
5 | 5 | TestCase, run_module_suite, assert_, assert_raises, assert_equal,
|
6 |
| - assert_warns, assert_array_equal, assert_array_almost_equal) |
| 6 | + assert_warns, assert_no_warnings, assert_array_equal, |
| 7 | + assert_array_almost_equal) |
7 | 8 | from numpy.compat import asbytes
|
8 | 9 | import sys
|
9 | 10 | import warnings
|
@@ -614,28 +615,37 @@ def test_multinomial(self):
|
614 | 615 | def test_multivariate_normal(self):
|
615 | 616 | mt19937.seed(self.seed)
|
616 | 617 | mean = (.123456789, 10)
|
617 |
| - # Hmm... not even symmetric. |
618 |
| - cov = [[1, 0], [1, 0]] |
| 618 | + cov = [[1, 0], [0, 1]] |
619 | 619 | size = (3, 2)
|
620 | 620 | actual = mt19937.multivariate_normal(mean, cov, size)
|
621 |
| - desired = np.array([[[-1.47027513018564449, 10.], |
622 |
| - [-1.65915081534845532, 10.]], |
623 |
| - [[-2.29186329304599745, 10.], |
624 |
| - [-1.77505606019580053, 10.]], |
625 |
| - [[-0.54970369430044119, 10.], |
626 |
| - [0.29768848031692957, 10.]]]) |
| 621 | + desired = np.array([[[1.463620246718631, 11.73759122771936 ], |
| 622 | + [1.622445133300628, 9.771356667546383]], |
| 623 | + [[2.154490787682787, 12.170324946056553], |
| 624 | + [1.719909438201865, 9.230548443648306]], |
| 625 | + [[0.689515026297799, 9.880729819607714], |
| 626 | + [-0.023054015651998, 9.201096623542879]]]) |
| 627 | + |
627 | 628 | assert_array_almost_equal(actual, desired, decimal=15)
|
628 | 629 |
|
629 | 630 | # Check for default size, was raising deprecation warning
|
630 | 631 | actual = mt19937.multivariate_normal(mean, cov)
|
631 |
| - desired = np.array([-0.79441224511977482, 10.]) |
| 632 | + desired = np.array([0.895289569463708, 9.17180864067987]) |
632 | 633 | assert_array_almost_equal(actual, desired, decimal=15)
|
633 | 634 |
|
634 |
| - # Check that non positive-semidefinite covariance raises warning |
| 635 | + # Check that non positive-semidefinite covariance warns with |
| 636 | + # RuntimeWarning |
635 | 637 | mean = [0, 0]
|
636 |
| - cov = [[1, 1 + 1e-10], [1 + 1e-10, 1]] |
| 638 | + cov = [[1, 2], [2, 1]] |
637 | 639 | assert_warns(RuntimeWarning, mt19937.multivariate_normal, mean, cov)
|
638 | 640 |
|
| 641 | + # and that it doesn't warn with RuntimeWarning check_valid='ignore' |
| 642 | + assert_no_warnings(mt19937.multivariate_normal, mean, cov, |
| 643 | + check_valid='ignore') |
| 644 | + |
| 645 | + # and that it raises with RuntimeWarning check_valid='raises' |
| 646 | + assert_raises(ValueError, mt19937.multivariate_normal, mean, cov, |
| 647 | + check_valid='raise') |
| 648 | + |
639 | 649 | def test_negative_binomial(self):
|
640 | 650 | mt19937.seed(self.seed)
|
641 | 651 | actual = mt19937.negative_binomial(n=100, p=.12345, size=(3, 2))
|
@@ -810,7 +820,9 @@ def test_uniform_range_bounds(self):
|
810 | 820 | assert_raises(OverflowError, func, [0], [np.inf])
|
811 | 821 |
|
812 | 822 | # (fmax / 1e17) - fmin is within range, so this should not throw
|
813 |
| - mt19937.uniform(low=fmin, high=fmax / 1e17) |
| 823 | + # account for i386 extended precision DBL_MAX / 1e17 + DBL_MAX > |
| 824 | + # DBL_MAX by increasing fmin a bit |
| 825 | + mt19937.uniform(low=np.nextafter(fmin, 1), high=fmax / 1e17) |
814 | 826 |
|
815 | 827 | def test_vonmises(self):
|
816 | 828 | mt19937.seed(self.seed)
|
|
0 commit comments