diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-10-25 12:34:31 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-10-25 12:34:31 -0700 |
commit | 47b5af987bf31553329334fa08898dac67dbf1ac (patch) | |
tree | 0dc8194b41d718024296962ab1502ef9621aab19 /numpy/linalg/tests/test_linalg.py | |
parent | 103abc22f803cd825a12c9ec900df26b34d501df (diff) | |
parent | f8e07275f05e95a4d0af098b06d37925602f7861 (diff) | |
download | numpy-47b5af987bf31553329334fa08898dac67dbf1ac.tar.gz |
Merge pull request #3978 from juliantaylor/py3-eigh-bug
BUG: fix broken UPLO of eigh in python3
Diffstat (limited to 'numpy/linalg/tests/test_linalg.py')
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index cc1404bf1..803b4c88f 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -728,7 +728,7 @@ class TestEigh(HermitianTestCase, HermitianGeneralizedTestCase): assert_allclose(dot_generalized(a, evc2), np.asarray(ev2)[...,None,:] * np.asarray(evc2), - rtol=get_rtol(ev.dtype)) + rtol=get_rtol(ev.dtype), err_msg=repr(a)) def test_types(self): def check(dtype): @@ -739,6 +739,53 @@ class TestEigh(HermitianTestCase, HermitianGeneralizedTestCase): for dtype in [single, double, csingle, cdouble]: yield check, dtype + def test_invalid(self): + x = np.array([[1, 0.5], [0.5, 1]], dtype=np.float32) + assert_raises(ValueError, np.linalg.eigh, x, UPLO="lrong") + assert_raises(ValueError, np.linalg.eigh, x, "lower") + assert_raises(ValueError, np.linalg.eigh, x, "upper") + assert_raises(ValueError, np.linalg.eigvalsh, x, UPLO="lrong") + assert_raises(ValueError, np.linalg.eigvalsh, x, "lower") + assert_raises(ValueError, np.linalg.eigvalsh, x, "upper") + + def test_half_filled(self): + expect = np.array([-0.33333333, -0.33333333, -0.33333333, 0.99999999]) + K = np.array([[ 0. , 0. , 0. , 0. ], + [-0.33333333, 0. , 0. , 0. ], + [ 0.33333333, -0.33333333, 0. , 0. ], + [ 0.33333333, -0.33333333, 0.33333333, 0. ]]) + Kr = np.rot90(K, k=2) + + w, V = np.linalg.eigh(K) + assert_allclose(np.sort(w), expect, rtol=get_rtol(K.dtype)) + + w, V = np.linalg.eigh(UPLO='L', a=K) + assert_allclose(np.sort(w), expect, rtol=get_rtol(K.dtype)) + w, V = np.linalg.eigh(K, 'l') + w2, V2 = np.linalg.eigh(K, 'L') + assert_allclose(w, w2, rtol=get_rtol(K.dtype)) + assert_allclose(V, V2, rtol=get_rtol(K.dtype)) + + w, V = np.linalg.eigh(Kr, 'U') + assert_allclose(np.sort(w), expect, rtol=get_rtol(K.dtype)) + w, V = np.linalg.eigh(Kr, 'u') + w2, V2 = np.linalg.eigh(Kr, 'u') + assert_allclose(w, w2, rtol=get_rtol(K.dtype)) + assert_allclose(V, V2, rtol=get_rtol(K.dtype)) + + w = np.linalg.eigvalsh(K) + assert_allclose(np.sort(w), expect, rtol=get_rtol(K.dtype)) + + w = np.linalg.eigvalsh(UPLO='L', a=K) + assert_allclose(np.sort(w), expect, rtol=get_rtol(K.dtype)) + assert_allclose(np.linalg.eigvalsh(K, 'L'), + np.linalg.eigvalsh(K, 'l'), rtol=get_rtol(K.dtype)) + + w = np.linalg.eigvalsh(Kr, 'U') + assert_allclose(np.sort(w), expect, rtol=get_rtol(K.dtype)) + assert_allclose(np.linalg.eigvalsh(Kr, 'U'), + np.linalg.eigvalsh(Kr, 'u'), rtol=get_rtol(K.dtype)) + class _TestNorm(object): |