From 4146c14e4a90f775f61ad863624b4f772fa8a40c Mon Sep 17 00:00:00 2001
From: Felix Schindler <felix.schindler@wwu.de>
Date: Wed, 22 Nov 2017 18:38:04 +0100
Subject: [PATCH] [test.eigensolver...eigens_example] improve expectations

---
 ...ensolver_for_matrix_from_eigens_example.cc | 61 +++++++++----------
 1 file changed, 29 insertions(+), 32 deletions(-)

diff --git a/dune/xt/la/test/eigensolver_for_matrix_from_eigens_example.cc b/dune/xt/la/test/eigensolver_for_matrix_from_eigens_example.cc
index 02d2bd227..5f63ef14a 100644
--- a/dune/xt/la/test/eigensolver_for_matrix_from_eigens_example.cc
+++ b/dune/xt/la/test/eigensolver_for_matrix_from_eigens_example.cc
@@ -17,8 +17,6 @@
 /**
  * \sa http://eigen.tuxfamily.org/dox/classEigen_1_1EigenSolver.html
  *
- * \note Ours might be quite a bit off, since we only have the truncated representations from the example.
- *
 \code
 Example:
 MatrixXd A = MatrixXd::Random(6,6);
@@ -94,34 +92,27 @@ struct EigenSolverForMatrixFromEigensExample : public EigenSolverTest
 
   EigenSolverForMatrixFromEigensExample()
   {
-    matrix_ = XT::Common::from_string<MatrixType>("[ 0.68  -0.33   -0.27   -0.717  -0.687  0.0259;"
-                                                  " -0.211  0.536   0.0268  0.214  -0.198  0.678;"
-                                                  "  0.566 -0.444   0.904  -0.967  -0.74   0.225;"
-                                                  "  0.597  0.108   0.832  -0.514  -0.782 -0.408;"
-                                                  "  0.823 -0.0452  0.271  -0.726   0.998  0.275;"
-                                                  " -0.605  0.258   0.435   0.608  -0.563  0.0486]");
-    // these values were recorded using lapack
-    expected_eigenvalues_ = XT::Common::from_string<EigenValuesType>("[0.048829697485156004+1.0596562712819182i "
-                                                                     " 0.048829697485156004-1.0596562712819182i "
-                                                                     " 0.96873863535292992 "
-                                                                     " 0.34280071327659634 "
-                                                                     " 0.62170062820008098+0.13733227413092269i "
-                                                                     " 0.62170062820008098-0.13733227413092269i]");
+    // these are the numbers in std::setprecision(17) from the above example
+    matrix_ = XT::Common::from_string<MatrixType>( // clang-format off
+                "[ 0.68037543430941905 -0.32955448857022196  -0.27043105441631332  -0.7167948892883933  -0.68664182149183084  0.025864788808796835; "
+                " -0.21123414636181392  0.53645918962380801   0.026801820391231024  0.21393775251411729 -0.198111211507633    0.67822446938521441; "
+                "  0.56619844751721171 -0.44445057839362445   0.90445945034942565  -0.96739885675134085 -0.74041910643708853  0.22527966519132248; "
+                "  0.59688006695214657  0.10793991159086103   0.8323901360074013   -0.51422645874052608 -0.78238239594846148 -0.40793676460531392; "
+                "  0.82329471587356862 -0.045205896275679502  0.27142345591980188  -0.72553684642796257  0.99784903600711794  0.27510453540603841; "
+                " -0.60489726141323208  0.25774184952384882   0.43459385886536617   0.60835350845398084 -0.56348618937818618  0.048574380133568518]");
+    expected_eigenvalues_ = XT::Common::from_string<EigenValuesType>("[0.048963596941571319+1.0595752114710908i "
+                                                                     " 0.048963596941571319-1.0595752114710908i "
+                                                                     " 0.96689928885360044 "
+                                                                     " 0.35304325510300372 "
+                                                                     " 0.61781064692153476+0.12941286410485134i "
+                                                                     " 0.61781064692153476-0.12941286410485134i]");
     expected_eigenvectors_ = XT::Common::from_string<ComplexMatrixType>(
-        "["
-        "-0.27012632227983902-0.46678683793394776i -0.27012632227983902+0.46678683793394776i -0.058555145136596501 "
-        "-0.72934250003563827 -0.59311240459518533 -0.59311240459518533; "
-        " 0.13887686287144707-0.097771882383961992i 0.13887686287144707+0.097771882383961992i -0.79902060638186234   "
-        "0.14851614296331883 -0.23987153829467844-0.45143010420135704i -0.23987153829467844+0.45143010420135704i; "
-        " -0.41364142584806307-0.19917683735545064i -0.41364142584806307+0.19917683735545064i 0.18949926740896209 "
-        "0.04700276597877924 0.29529738066681194+0.21971404267746528i 0.29529738066681194-0.21971404267746528i; "
-        " -0.58911879728583405 -0.58911879728583405 -0.078813329494931098 -0.63174635015851877 "
-        "-0.33835579668284677+0.092082191690773141i -0.33835579668284677-0.092082191690773141i; "
-        " -0.2538014452885316+0.12001744521279049i -0.2538014452885316-0.12001744521279049i 0.40135933686903708 "
-        "0.21115859793042213 0.30424687115889376+0.14919085125463472i 0.30424687115889376-0.14919085125463472i; "
-        " 0.097132120486031412+0.18495968552407643i  0.097132120486031412-0.18495968552407643i -0.39360708201025785 "
-        "-0.010090019467593912 0.060511969188928441-0.099829032727048669i 0.060511969188928441+0.099829032727048669i "
-        "]");
+        "[-0.2916493853334598-0.45353428327568535i   -0.2916493853334598+0.45353428327568535i   -0.060739856420097799 -0.732892086787302      0.58989693747516225-0.12134050155506512i   0.58989693747516225+0.12134050155506512i; "
+        "  0.13427786119296695-0.10415042620914604i   0.13427786119296695+0.10415042620914604i  -0.79936618427058692   0.13588801812778584    0.33446578429890217+0.36779173930086734i   0.33446578429890217-0.36779173930086734i; "
+        " -0.4224933428958097-0.17959111262899077i   -0.4224933428958097+0.17959111262899077i    0.19181897363210443   0.056319404917871921  -0.33512506847695012-0.1433533445630015i   -0.33512506847695012+0.1433533445630015i; "
+        " -0.58861043190958418+0.027350002433760786i -0.58861043190958418-0.027350002433760786i -0.078824737066622547 -0.62743714713230025    0.32187174947115971-0.1554720757387448i    0.32187174947115971+0.1554720757387448i; "
+        " -0.24767280752759105+0.13196040251638746i  -0.24767280752759105-0.13196040251638746i   0.40098186135709829   0.21799673455433938   -0.33488773557308854-0.076133571019896026i -0.33488773557308854+0.076133571019896026i; "
+        "  0.10538083226488951+0.18040258229827225i   0.10538083226488951-0.18040258229827225i  -0.39182912389260799  -0.0056400714249183401 -0.032444861799488058+0.10261186083116479i -0.032444861799488058-0.10261186083116479i]"); // clang-format on
     all_matrices_and_expected_eigenvalues_and_vectors_are_computed_ = true;
   }
 
@@ -164,15 +155,21 @@ TEST_F(EigenSolverForMatrixFromEigensExample, is_constructible)
 
 TEST_F(EigenSolverForMatrixFromEigensExample, gives_correct_eigenvalues)
 {
-  gives_correct_eigenvalues({{"lapack", "1e-15"}, {"eigen", "1e-14"}});
+  gives_correct_eigenvalues({{"lapack", "1e-14"}, {"numpy", "1e-14"}});
 }
 
 TEST_F(EigenSolverForMatrixFromEigensExample, gives_correct_eigenvalues_in_correct_order)
 {
-  gives_correct_eigenvalues_in_correct_order({{"lapack", "1e-15"}, {"eigen", "1e-14"}});
+  gives_correct_eigenvalues_in_correct_order({{"lapack", "1e-14"}, {"numpy", "1e-14"}});
+}
+
+TEST_F(EigenSolverForMatrixFromEigensExample, gives_correct_eigenvectors_in_correct_order)
+{
+  gives_correct_eigenvectors_in_correct_order(
+      {{"lapack", /*we expect a failure: */ "-1"}, {"numpy", /*we expect a failure: */ "-1"}});
 }
 
 TEST_F(EigenSolverForMatrixFromEigensExample, gives_correct_eigendecomposition)
 {
-  gives_correct_eigendecomposition(1e-14);
+  gives_correct_eigendecomposition({{"lapack", "1e-14"}, {"eigen", "1e-14"}, {"numpy", "1e-14"}});
 }
-- 
GitLab