Skip to content

Commit d6fed32

Browse files
committed
Merge pull request #184 from matthew-brett/mahalanobis-numerics
TEST: relax threshold for Mahalanobis test We were getting test failures sometimes for Mahalanobis, of form:: Arrays are not almost equal ACTUAL: 334932.87269147561 DESIRED: 334932.87480824895 Relax threshold by asserting np.allclose instead of assert_almost_equal.
2 parents 671701e + f9484f8 commit d6fed32

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

nipy/labs/utils/tests/test_misc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import numpy as np
44
from scipy import special
55

6-
from numpy.testing import assert_almost_equal, assert_equal, TestCase
7-
86
from ..routines import median, mahalanobis, gamln, psi
97

8+
from nose.tools import assert_true
9+
from numpy.testing import assert_almost_equal, assert_equal, TestCase
10+
1011

1112
class TestAll(TestCase):
1213

@@ -28,7 +29,7 @@ def test_mahalanobis(self):
2829
A = np.dot(A.transpose(), A) + np.eye(100)
2930
mah = np.dot(x, np.dot(np.linalg.inv(A), x))
3031
assert_almost_equal(mah, mahalanobis(x, A), decimal=1)
31-
32+
3233
def test_mahalanobis2(self):
3334
x = np.random.rand(100,3,4)
3435
Aa = np.zeros([100,100,3,4])
@@ -40,9 +41,9 @@ def test_mahalanobis2(self):
4041
i = np.random.randint(3)
4142
j = np.random.randint(4)
4243
mah = np.dot(x[:,i,j], np.dot(np.linalg.inv(Aa[:,:,i,j]), x[:,i,j]))
43-
f_mah = (mahalanobis(x, Aa))[i,j]
44-
assert_almost_equal(mah, f_mah, decimal=3)
45-
44+
f_mah = (mahalanobis(x, Aa))[i,j]
45+
assert_true(np.allclose(mah, f_mah))
46+
4647
def test_gamln(self):
4748
for x in (0.01+100*np.random.random(50)):
4849
scipy_gamln = special.gammaln(x)

0 commit comments

Comments
 (0)