summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorAlan McIntyre <alan.mcintyre@local>2008-07-14 00:27:38 +0000
committerAlan McIntyre <alan.mcintyre@local>2008-07-14 00:27:38 +0000
commite227d01fdd75f2b8d10cefe057ca7847063f769d (patch)
tree963238d986a2bf86a5a1c138cf291b116d242c84 /numpy
parent39e305137d5d3df233d87b3fb903fcdc81750d65 (diff)
downloadnumpy-e227d01fdd75f2b8d10cefe057ca7847063f769d.tar.gz
Added tests for eigenvalue/vector functions for Hermitian matrices..
Diffstat (limited to 'numpy')
-rw-r--r--numpy/linalg/tests/test_linalg.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index 441eede1a..8fd8b72ed 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -202,5 +202,60 @@ class TestBoolPower(TestCase):
assert_equal(matrix_power(A,2),A)
+class HermitianTestCase:
+ def test_single(self):
+ a = array([[1.,2.], [2.,1.]], dtype=single)
+ self.do(a)
+
+ def test_double(self):
+ a = array([[1.,2.], [2.,1.]], dtype=double)
+ self.do(a)
+
+ def test_csingle(self):
+ a = array([[1.,2+3j], [2-3j,1]], dtype=csingle)
+ self.do(a)
+
+ def test_cdouble(self):
+ a = array([[1.,2+3j], [2-3j,1]], dtype=cdouble)
+ self.do(a)
+
+ def test_empty(self):
+ a = atleast_2d(array([], dtype = double))
+ assert_raises(linalg.LinAlgError, self.do, a)
+
+ def test_nonarray(self):
+ a = [[1,2], [2,1]]
+ self.do(a)
+
+ def test_matrix_b_only(self):
+ """Check that matrix type is preserved."""
+ a = array([[1.,2.], [2.,1.]])
+ self.do(a)
+
+ def test_matrix_a_and_b(self):
+ """Check that matrix type is preserved."""
+ a = matrix([[1.,2.], [2.,1.]])
+ self.do(a)
+
+class TestEigvalsh(HermitianTestCase, TestCase):
+ def do(self, a):
+ ev = linalg.eigvalsh(a)
+ # flip resulting eigenvalue array, since they are returned in
+ # reverse order from the values given by linal.eig
+ ev = ev[::-1]
+
+ evalues, evectors = linalg.eig(a)
+ assert_almost_equal(ev, evalues)
+
+class TestEigh(HermitianTestCase, TestCase):
+ def do(self, a):
+ ev, evc = linalg.eigh(a)
+ # flip resulting eigenvalue array, since they are returned in
+ # reverse order from the values given by linal.eig
+ ev = ev[::-1]
+
+ evalues, evectors = linalg.eig(a)
+ assert_almost_equal(ev, evalues)
+
if __name__ == "__main__":
run_module_suite()