From c41b49fa8e9f1e794e8245aad7f63960167121b6 Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:44:34 -0400 Subject: [PATCH 01/11] added the calculation method of diagonal matrix to `takagi`, and test matrix to test_decompositions.py. --- .github/CHANGELOG.md | 2 ++ thewalrus/decompositions.py | 9 +++++++++ thewalrus/tests/test_decompositions.py | 8 ++++++++ thewalrus/tests/test_matrix_for_takagi.npy | Bin 0 -> 272 bytes 4 files changed, 19 insertions(+) create mode 100644 thewalrus/tests/test_matrix_for_takagi.npy diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 66dc415a..056b0f52 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -15,6 +15,8 @@ ### Bug fixes +* Add the calculation method of `takagi` when the matrix is diagonal. + ### Documentation ### Contributors diff --git a/thewalrus/decompositions.py b/thewalrus/decompositions.py index 46585429..01ef8b5a 100644 --- a/thewalrus/decompositions.py +++ b/thewalrus/decompositions.py @@ -202,6 +202,15 @@ def takagi(A, svd_order=True): vals, U = takagi(Amr, svd_order=svd_order) return vals, U * np.exp(1j * phi / 2) + # If the matrix is diagonal, Takagi decomposition is easy + if np.allclose(A, np.diag(np.diag(A))): + d = np.diag(A) + U = np.diag(np.exp(1j * 0.5 * np.angle(d))) + l = np.abs(d) + if svd_order is False: + return l[::-1], U[:, ::-1] + return l, U + u, d, v = np.linalg.svd(A) U = u @ sqrtm((v @ np.conjugate(u)).T) if svd_order is False: diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index 122c0821..b1e1b5f2 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -323,6 +323,14 @@ def test_takagi_error(): with pytest.raises(ValueError, match="The input matrix is not square"): takagi(A) +def test_takagi_sepcific_matrix(): + """Test the takagi decomposition works well for a specific matrix that was not deecomposed accuratelyin a previous version. + See more info in PR #393 (https://github.com/XanaduAI/thewalrus/pull/393)""" + A = np.load('test_matrix_for_takagi.npy') + d, U = takagi(A) + assert np.allclose(A, U @ np.diag(d) @ U.T) + assert np.allclose(U @ np.conjugate(U).T, np.eye(len(U))) + assert np.all(d >= 0) def test_real_degenerate(): """Verify that the Takagi decomposition returns a matrix that is unitary and results in a diff --git a/thewalrus/tests/test_matrix_for_takagi.npy b/thewalrus/tests/test_matrix_for_takagi.npy new file mode 100644 index 0000000000000000000000000000000000000000..a63b28c2cd149557c9988c48d47c63528f76da40 GIT binary patch literal 272 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlWb_FuA`uymS0p-l$aNvUzCyxl5k7RDNY57 z7iT0EqyqUG#ySednmP)#3giMV?y8#+EZnd6>+NBvX}>bpW)*Y)>KWmaZ06oh5MB}B zywkX@SeQL3(Q+T3 Date: Fri, 5 Jul 2024 12:15:22 -0400 Subject: [PATCH 02/11] added the related pull request number into CHANGELOG.md. --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 056b0f52..392e5d28 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -15,7 +15,7 @@ ### Bug fixes -* Add the calculation method of `takagi` when the matrix is diagonal. +* Add the calculation method of `takagi` when the matrix is diagonal. [(#394)](https://github.com/XanaduAI/thewalrus/pull/394) ### Documentation From 6e9b2b5625146856a904895b7a32c912cfeef64a Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:43:27 -0400 Subject: [PATCH 03/11] Update thewalrus/tests/test_decompositions.py Co-authored-by: Nicolas Quesada <991946+nquesada@users.noreply.github.com> --- thewalrus/tests/test_decompositions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index b1e1b5f2..dc467159 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -323,7 +323,7 @@ def test_takagi_error(): with pytest.raises(ValueError, match="The input matrix is not square"): takagi(A) -def test_takagi_sepcific_matrix(): +def test_takagi_diagonal_matrix(): """Test the takagi decomposition works well for a specific matrix that was not deecomposed accuratelyin a previous version. See more info in PR #393 (https://github.com/XanaduAI/thewalrus/pull/393)""" A = np.load('test_matrix_for_takagi.npy') From 137820ea7c1adba25c881de9a22e0746f3a334ae Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:46:32 -0400 Subject: [PATCH 04/11] added rtol to np.allclose, corrected the sort of l and U, and added the diagonal matrix explicitly to test_decompositions.py. --- thewalrus/decompositions.py | 6 ++++-- thewalrus/tests/test_decompositions.py | 4 +++- thewalrus/tests/test_matrix_for_takagi.npy | Bin 272 -> 0 bytes 3 files changed, 7 insertions(+), 3 deletions(-) delete mode 100644 thewalrus/tests/test_matrix_for_takagi.npy diff --git a/thewalrus/decompositions.py b/thewalrus/decompositions.py index 01ef8b5a..0dfee9f7 100644 --- a/thewalrus/decompositions.py +++ b/thewalrus/decompositions.py @@ -203,11 +203,13 @@ def takagi(A, svd_order=True): return vals, U * np.exp(1j * phi / 2) # If the matrix is diagonal, Takagi decomposition is easy - if np.allclose(A, np.diag(np.diag(A))): + if np.allclose(A, np.diag(np.diag(A)), rtol=1e-16): d = np.diag(A) U = np.diag(np.exp(1j * 0.5 * np.angle(d))) l = np.abs(d) - if svd_order is False: + l = np.sort(l) + U = U[np.argsort(l)] + if svd_order: return l[::-1], U[:, ::-1] return l, U diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index b1e1b5f2..d1e6ff81 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -326,7 +326,9 @@ def test_takagi_error(): def test_takagi_sepcific_matrix(): """Test the takagi decomposition works well for a specific matrix that was not deecomposed accuratelyin a previous version. See more info in PR #393 (https://github.com/XanaduAI/thewalrus/pull/393)""" - A = np.load('test_matrix_for_takagi.npy') + A = np.array([[-8.4509484628125742e-01+1.0349426984742664e-16j, 6.3637197288239186e-17-7.4398922703555097e-33j, 2.6734481396039929e-32+1.7155650257063576e-35j], + [ 6.3637197288239186e-17-7.4398922703555097e-33j, -2.0594021562561332e-01+2.2863956908382538e-17j, -5.8325863096557049e-17+1.6949718400585382e-18j], + [ 2.6734481396039929e-32+1.7155650257063576e-35j, -5.8325863096557049e-17+1.6949718400585382e-18j, 4.4171453199503476e-02+1.0022350742842835e-02j]]) d, U = takagi(A) assert np.allclose(A, U @ np.diag(d) @ U.T) assert np.allclose(U @ np.conjugate(U).T, np.eye(len(U))) diff --git a/thewalrus/tests/test_matrix_for_takagi.npy b/thewalrus/tests/test_matrix_for_takagi.npy deleted file mode 100644 index a63b28c2cd149557c9988c48d47c63528f76da40..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 272 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlWb_FuA`uymS0p-l$aNvUzCyxl5k7RDNY57 z7iT0EqyqUG#ySednmP)#3giMV?y8#+EZnd6>+NBvX}>bpW)*Y)>KWmaZ06oh5MB}B zywkX@SeQL3(Q+T3 Date: Fri, 5 Jul 2024 13:55:44 -0400 Subject: [PATCH 05/11] reformat test_decompositions.py using black --- thewalrus/tests/test_decompositions.py | 52 +++++++++++++++++++++----- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index d2416c30..a819eeb7 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -19,7 +19,13 @@ from thewalrus.random import random_interferometer as haar_measure from thewalrus.random import random_symplectic -from thewalrus.decompositions import williamson, blochmessiah, takagi, pre_iwasawa, iwasawa +from thewalrus.decompositions import ( + williamson, + blochmessiah, + takagi, + pre_iwasawa, + iwasawa, +) from thewalrus.symplectic import sympmat as omega from thewalrus.quantum.gaussian_checks import is_symplectic @@ -48,7 +54,9 @@ def _create_cov(nbar): # interferometer 1 U1 = haar_measure(n) - S1 = np.vstack([np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])]) + S1 = np.vstack( + [np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])] + ) # squeezing r = np.log(0.2 * np.arange(n) + 2) @@ -56,7 +64,9 @@ def _create_cov(nbar): # interferometer 2 U2 = haar_measure(n) - S2 = np.vstack([np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])]) + S2 = np.vstack( + [np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])] + ) # final symplectic S_final = S2 @ Sq @ S1 @@ -99,7 +109,9 @@ def test_even_validation(self): """Test that the graph_embed decomposition raises exception if not even number of rows""" A = np.random.rand(5, 5) + 1j * np.random.rand(5, 5) A += A.T - with pytest.raises(ValueError, match="must have an even number of rows/columns"): + with pytest.raises( + ValueError, match="must have an even number of rows/columns" + ): williamson(A) def test_positive_definite_validation(self): @@ -172,7 +184,9 @@ def _create_transform(n, passive=True): # interferometer 1 U1 = haar_measure(n) - S1 = np.vstack([np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])]) + S1 = np.vstack( + [np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])] + ) Sq = np.identity(2 * n) if not passive: @@ -182,7 +196,9 @@ def _create_transform(n, passive=True): # interferometer 2 U2 = haar_measure(n) - S2 = np.vstack([np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])]) + S2 = np.vstack( + [np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])] + ) # final symplectic S_final = S2 @ Sq @ S1 @@ -323,17 +339,35 @@ def test_takagi_error(): with pytest.raises(ValueError, match="The input matrix is not square"): takagi(A) + def test_takagi_diagonal_matrix(): """Test the takagi decomposition works well for a specific matrix that was not deecomposed accuratelyin a previous version. See more info in PR #393 (https://github.com/XanaduAI/thewalrus/pull/393)""" - A = np.array([[-8.4509484628125742e-01+1.0349426984742664e-16j, 6.3637197288239186e-17-7.4398922703555097e-33j, 2.6734481396039929e-32+1.7155650257063576e-35j], - [ 6.3637197288239186e-17-7.4398922703555097e-33j, -2.0594021562561332e-01+2.2863956908382538e-17j, -5.8325863096557049e-17+1.6949718400585382e-18j], - [ 2.6734481396039929e-32+1.7155650257063576e-35j, -5.8325863096557049e-17+1.6949718400585382e-18j, 4.4171453199503476e-02+1.0022350742842835e-02j]]) + A = np.array( + [ + [ + -8.4509484628125742e-01 + 1.0349426984742664e-16j, + 6.3637197288239186e-17 - 7.4398922703555097e-33j, + 2.6734481396039929e-32 + 1.7155650257063576e-35j, + ], + [ + 6.3637197288239186e-17 - 7.4398922703555097e-33j, + -2.0594021562561332e-01 + 2.2863956908382538e-17j, + -5.8325863096557049e-17 + 1.6949718400585382e-18j, + ], + [ + 2.6734481396039929e-32 + 1.7155650257063576e-35j, + -5.8325863096557049e-17 + 1.6949718400585382e-18j, + 4.4171453199503476e-02 + 1.0022350742842835e-02j, + ], + ] + ) d, U = takagi(A) assert np.allclose(A, U @ np.diag(d) @ U.T) assert np.allclose(U @ np.conjugate(U).T, np.eye(len(U))) assert np.all(d >= 0) + def test_real_degenerate(): """Verify that the Takagi decomposition returns a matrix that is unitary and results in a correct decomposition when input a real but highly degenerate matrix. This test uses the From 7f1a7954c402e311bbc579d9a6305937d1cdad24 Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:57:58 -0400 Subject: [PATCH 06/11] Update thewalrus/tests/test_decompositions.py Co-authored-by: Nicolas Quesada <991946+nquesada@users.noreply.github.com> --- thewalrus/tests/test_decompositions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index a819eeb7..7f969a59 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -341,7 +341,7 @@ def test_takagi_error(): def test_takagi_diagonal_matrix(): - """Test the takagi decomposition works well for a specific matrix that was not deecomposed accuratelyin a previous version. + """Test the takagi decomposition works well for a specific matrix that was not decomposed accurately in a previous implementation. See more info in PR #393 (https://github.com/XanaduAI/thewalrus/pull/393)""" A = np.array( [ From cf82481edf806670ebf8461ddf470cfe9b0c6770 Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:29:47 -0400 Subject: [PATCH 07/11] added pylint: disable=too-many-return-statements. fixed the ordering of the matrix in takagi with diagonal matrix --- thewalrus/decompositions.py | 8 +++++--- thewalrus/tests/test_decompositions.py | 8 +------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/thewalrus/decompositions.py b/thewalrus/decompositions.py index 0dfee9f7..a8ae2d3e 100644 --- a/thewalrus/decompositions.py +++ b/thewalrus/decompositions.py @@ -153,6 +153,7 @@ def blochmessiah(S): def takagi(A, svd_order=True): + # pylint: disable=too-many-return-statements r"""Autonne-Takagi decomposition of a complex symmetric (not Hermitian!) matrix. Note that the input matrix is internally symmetrized by taking its upper triangular part. If the input matrix is indeed symmetric this leaves it unchanged. @@ -207,10 +208,11 @@ def takagi(A, svd_order=True): d = np.diag(A) U = np.diag(np.exp(1j * 0.5 * np.angle(d))) l = np.abs(d) - l = np.sort(l) - U = U[np.argsort(l)] + idx = np.argsort(l) + l = l[idx] + U = U[idx] if svd_order: - return l[::-1], U[:, ::-1] + return l[::-1], U[::-1, :] return l, U u, d, v = np.linalg.svd(A) diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index 7f969a59..5da07ac0 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -19,13 +19,7 @@ from thewalrus.random import random_interferometer as haar_measure from thewalrus.random import random_symplectic -from thewalrus.decompositions import ( - williamson, - blochmessiah, - takagi, - pre_iwasawa, - iwasawa, -) +from thewalrus.decompositions import williamson, blochmessiah, takagi, pre_iwasawa, iwasawa from thewalrus.symplectic import sympmat as omega from thewalrus.quantum.gaussian_checks import is_symplectic From 74c05b87af5038233fa3eeae2e79435ed6e27075 Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:02:44 -0400 Subject: [PATCH 08/11] fixed the ordering of the matrix in takagi with diagonal matrix added test to trigger both svd_order=True and False in takagi with diagonal matrix --- thewalrus/decompositions.py | 7 ++++--- thewalrus/tests/test_decompositions.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/thewalrus/decompositions.py b/thewalrus/decompositions.py index a8ae2d3e..df490513 100644 --- a/thewalrus/decompositions.py +++ b/thewalrus/decompositions.py @@ -206,13 +206,14 @@ def takagi(A, svd_order=True): # If the matrix is diagonal, Takagi decomposition is easy if np.allclose(A, np.diag(np.diag(A)), rtol=1e-16): d = np.diag(A) - U = np.diag(np.exp(1j * 0.5 * np.angle(d))) l = np.abs(d) idx = np.argsort(l) + d = d[idx] l = l[idx] - U = U[idx] + U = np.diag(np.exp(1j * 0.5 * np.angle(d))) + U = U[::-1, :] if svd_order: - return l[::-1], U[::-1, :] + return l[::-1], U[:, ::-1] return l, U u, d, v = np.linalg.svd(A) diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index 5da07ac0..1a9e9b82 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -334,7 +334,8 @@ def test_takagi_error(): takagi(A) -def test_takagi_diagonal_matrix(): +@pytest.mark.parametrize("svd_order", [True, False]) +def test_takagi_diagonal_matrix(svd_order): """Test the takagi decomposition works well for a specific matrix that was not decomposed accurately in a previous implementation. See more info in PR #393 (https://github.com/XanaduAI/thewalrus/pull/393)""" A = np.array( @@ -356,7 +357,7 @@ def test_takagi_diagonal_matrix(): ], ] ) - d, U = takagi(A) + d, U = takagi(A, svd_order=svd_order) assert np.allclose(A, U @ np.diag(d) @ U.T) assert np.allclose(U @ np.conjugate(U).T, np.eye(len(U))) assert np.all(d >= 0) From c81cfbb8ba8bbae3a6a7a0247d6bcef3def2612f Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:36:03 -0400 Subject: [PATCH 09/11] reformated test_decompositions.py using black -l 100 --- thewalrus/tests/test_decompositions.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/thewalrus/tests/test_decompositions.py b/thewalrus/tests/test_decompositions.py index 1a9e9b82..18e3adf6 100644 --- a/thewalrus/tests/test_decompositions.py +++ b/thewalrus/tests/test_decompositions.py @@ -48,9 +48,7 @@ def _create_cov(nbar): # interferometer 1 U1 = haar_measure(n) - S1 = np.vstack( - [np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])] - ) + S1 = np.vstack([np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])]) # squeezing r = np.log(0.2 * np.arange(n) + 2) @@ -58,9 +56,7 @@ def _create_cov(nbar): # interferometer 2 U2 = haar_measure(n) - S2 = np.vstack( - [np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])] - ) + S2 = np.vstack([np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])]) # final symplectic S_final = S2 @ Sq @ S1 @@ -103,9 +99,7 @@ def test_even_validation(self): """Test that the graph_embed decomposition raises exception if not even number of rows""" A = np.random.rand(5, 5) + 1j * np.random.rand(5, 5) A += A.T - with pytest.raises( - ValueError, match="must have an even number of rows/columns" - ): + with pytest.raises(ValueError, match="must have an even number of rows/columns"): williamson(A) def test_positive_definite_validation(self): @@ -178,9 +172,7 @@ def _create_transform(n, passive=True): # interferometer 1 U1 = haar_measure(n) - S1 = np.vstack( - [np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])] - ) + S1 = np.vstack([np.hstack([U1.real, -U1.imag]), np.hstack([U1.imag, U1.real])]) Sq = np.identity(2 * n) if not passive: @@ -190,9 +182,7 @@ def _create_transform(n, passive=True): # interferometer 2 U2 = haar_measure(n) - S2 = np.vstack( - [np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])] - ) + S2 = np.vstack([np.hstack([U2.real, -U2.imag]), np.hstack([U2.imag, U2.real])]) # final symplectic S_final = S2 @ Sq @ S1 From 6fb38fed3c10879553dbc828bcdb440e3f24d669 Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:44:28 -0400 Subject: [PATCH 10/11] moved the rtol as an optional parameter of takagi --- thewalrus/decompositions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/thewalrus/decompositions.py b/thewalrus/decompositions.py index df490513..ba7c34d0 100644 --- a/thewalrus/decompositions.py +++ b/thewalrus/decompositions.py @@ -152,7 +152,7 @@ def blochmessiah(S): return O, D, Q -def takagi(A, svd_order=True): +def takagi(A, svd_order=True, rtol=1e-16): # pylint: disable=too-many-return-statements r"""Autonne-Takagi decomposition of a complex symmetric (not Hermitian!) matrix. Note that the input matrix is internally symmetrized by taking its upper triangular part. @@ -163,6 +163,7 @@ def takagi(A, svd_order=True): Args: A (array): square, symmetric matrix svd_order (boolean): whether to return result by ordering the singular values of ``A`` in descending (``True``) or ascending (``False``) order. + rtol (float): relative tolerance when judging if the matrix is diagonal or not. Returns: tuple[array, array]: (r, U), where r are the singular values, @@ -204,7 +205,7 @@ def takagi(A, svd_order=True): return vals, U * np.exp(1j * phi / 2) # If the matrix is diagonal, Takagi decomposition is easy - if np.allclose(A, np.diag(np.diag(A)), rtol=1e-16): + if np.allclose(A, np.diag(np.diag(A)), rtol=rtol): d = np.diag(A) l = np.abs(d) idx = np.argsort(l) From b5fbd06891f2b83141425ac0558940c7a60f0149 Mon Sep 17 00:00:00 2001 From: Ryosuke Noro <64354442+RyosukeNORO@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:53:38 -0400 Subject: [PATCH 11/11] updeted the description of rtol in takagi --- thewalrus/decompositions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thewalrus/decompositions.py b/thewalrus/decompositions.py index ba7c34d0..a0e65733 100644 --- a/thewalrus/decompositions.py +++ b/thewalrus/decompositions.py @@ -163,7 +163,7 @@ def takagi(A, svd_order=True, rtol=1e-16): Args: A (array): square, symmetric matrix svd_order (boolean): whether to return result by ordering the singular values of ``A`` in descending (``True``) or ascending (``False``) order. - rtol (float): relative tolerance when judging if the matrix is diagonal or not. + rtol (float): the relative tolerance parameter used in ``np.allclose`` when judging if the matrix is diagonal or not. Default to 1e-16. Returns: tuple[array, array]: (r, U), where r are the singular values,