- eigs1 = eigenvalues(mat)
- eigs2 = eigenvalues_re(mat)
- self.assertTrue(all([abs(e1 - 1) < ABS_TOL for e1 in eigs1]))
- self.assertTrue(all([abs(e2 - 1) < ABS_TOL for e2 in eigs2]))
+ eigs = eigenvalues(mat)
+ self.assertTrue(all([abs(ev - 1) < ABS_TOL for ev in eigs]))
+
+
+class EigenvaluesRealPartTest(TestCase):
+ """
+ Tests for the :func:`eigenvalues_re` function.
+ """
+
+ def test_eigenvalues_re_input_not_clobbered(self):
+ """
+ The eigenvalue functions provided by CVXOPT/LAPACK like to
+ overwrite the matrices that you pass into them as
+ arguments. This test makes sure that our :func:`eigenvalues_re`
+ function does not do the same.
+
+ We use a ``deepcopy`` here in case the ``copy`` used in the
+ :func:`eigenvalues_re` function is insufficient. If ``copy`` didn't
+ work and this test used it too, then this test would pass when
+ it shouldn't.
+ """
+ mat = random_matrix(random_natural())
+ mat_copy = deepcopy(mat)
+ dummy = eigenvalues_re(mat)
+ self.assertTrue(norm(mat - mat_copy) < ABS_TOL)
+
+ def test_eigenvalues_re_of_identity(self):
+ """
+ All eigenvalues of the identity matrix should be one.
+ """
+ mat = identity(random_natural(), typecode='d')
+ eigs = eigenvalues_re(mat)
+ self.assertTrue(all([abs(ev - 1) < ABS_TOL for ev in eigs]))