From ae1191b656654b18deeba44bb6ecc084f0b41737 Mon Sep 17 00:00:00 2001 From: CJ Carey Date: Thu, 2 Feb 2017 12:27:36 -0500 Subject: ENH: add hermitian=False kwarg to matrix_power With a symmetric matrix, the more efficient `eigvalsh` method can be used to find singular values. --- numpy/linalg/tests/test_linalg.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'numpy/linalg/tests') diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index fa20cc5ea..8b3984883 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -1383,6 +1383,19 @@ class TestMatrixRank(object): # works on scalar yield assert_equal, matrix_rank(1), 1 + def test_symmetric_rank(self): + yield assert_equal, 4, matrix_rank(np.eye(4), hermitian=True) + yield assert_equal, 1, matrix_rank(np.ones((4, 4)), hermitian=True) + yield assert_equal, 0, matrix_rank(np.zeros((4, 4)), hermitian=True) + # rank deficient matrix + I = np.eye(4) + I[-1, -1] = 0. + yield assert_equal, 3, matrix_rank(I, hermitian=True) + # manually supplied tolerance + I[-1, -1] = 1e-8 + yield assert_equal, 4, matrix_rank(I, hermitian=True, tol=0.99e-8) + yield assert_equal, 3, matrix_rank(I, hermitian=True, tol=1.01e-8) + def test_reduced_rank(): # Test matrices with reduced rank -- cgit v1.2.1