From 56ae9933561d38c75fc8ffcf137f4133e5ec9f31 Mon Sep 17 00:00:00 2001
From: Rene Milk <rene.milk@uni-muenster.de>
Date: Tue, 23 Jun 2015 18:56:05 +0200
Subject: [PATCH] [la/common] simplify std::complex hndling by providing
 DSC::{isnan,isinf}

---
 dune/stuff/la/container/common.hh           |  2 +-
 dune/stuff/la/container/eigen/dense.hh      |  2 +-
 dune/stuff/la/container/eigen/sparse.hh     |  2 +-
 dune/stuff/la/container/istl.hh             |  2 +-
 dune/stuff/la/container/vector-interface.hh |  3 ++-
 dune/stuff/la/solver/common.hh              |  2 +-
 dune/stuff/la/solver/eigen.hh               | 18 +++++++++---------
 dune/stuff/la/solver/istl.hh                |  2 +-
 8 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/dune/stuff/la/container/common.hh b/dune/stuff/la/container/common.hh
index 8e2e07f47..7dfcd8e7d 100644
--- a/dune/stuff/la/container/common.hh
+++ b/dune/stuff/la/container/common.hh
@@ -578,7 +578,7 @@ public:
       const auto& row_vec = backend_->operator[](ii);
       for (size_t jj = 0; jj < cols(); ++jj) {
         const auto& entry = row_vec[jj];
-        if (std::isnan(std::real(entry)) || std::isnan(std::imag(entry)) || std::isinf(std::abs(entry)))
+        if (Common::isnan(entry) || Common::isinf(entry))
           return false;
       }
     }
diff --git a/dune/stuff/la/container/eigen/dense.hh b/dune/stuff/la/container/eigen/dense.hh
index 6dcbf7372..357fbbeb1 100644
--- a/dune/stuff/la/container/eigen/dense.hh
+++ b/dune/stuff/la/container/eigen/dense.hh
@@ -603,7 +603,7 @@ public:
     for (size_t ii = 0; ii < rows(); ++ii) {
       for (size_t jj = 0; jj < cols(); ++jj) {
         const auto& entry = backend_->operator()(ii, jj);
-        if (std::isnan(std::real(entry)) || std::isnan(std::imag(entry)) || std::isinf(std::abs(entry)))
+        if (Common::isnan(entry) || Common::isinf(entry))
           return false;
       }
     }
diff --git a/dune/stuff/la/container/eigen/sparse.hh b/dune/stuff/la/container/eigen/sparse.hh
index 534c36ba3..31471f349 100644
--- a/dune/stuff/la/container/eigen/sparse.hh
+++ b/dune/stuff/la/container/eigen/sparse.hh
@@ -351,7 +351,7 @@ public:
     typedef typename BackendType::InnerIterator InnerIterator;
     for (EIGEN_size_t ii = 0; ii < backend_->outerSize(); ++ii) {
       for (InnerIterator it(*backend_, ii); it; ++it) {
-        if (std::isnan(std::real(it.value())) || std::isnan(std::imag(it.value())) || std::isinf(std::abs(it.value())))
+        if (DSC::isnan(std::real(it.value())) || DSC::isnan(std::imag(it.value())) || DSC::isinf(std::abs(it.value())))
           return false;
       }
     }
diff --git a/dune/stuff/la/container/istl.hh b/dune/stuff/la/container/istl.hh
index 0c462a7d7..b497863b0 100644
--- a/dune/stuff/la/container/istl.hh
+++ b/dune/stuff/la/container/istl.hh
@@ -609,7 +609,7 @@ public:
       for (size_t jj = 0; jj < cols(); ++jj)
         if (backend_->exists(ii, jj)) {
           const auto& entry = row_vec[jj][0];
-          if (std::isnan(std::real(entry[0])) || std::isnan(std::imag(entry[0])) || std::isinf(std::abs(entry[0])))
+          if (DSC::isnan(std::real(entry[0])) || DSC::isnan(std::imag(entry[0])) || DSC::isinf(std::abs(entry[0])))
             return false;
         }
     }
diff --git a/dune/stuff/la/container/vector-interface.hh b/dune/stuff/la/container/vector-interface.hh
index 629d74efd..e1dc4efa2 100644
--- a/dune/stuff/la/container/vector-interface.hh
+++ b/dune/stuff/la/container/vector-interface.hh
@@ -23,6 +23,7 @@
 #include <dune/stuff/common/float_cmp.hh>
 #include <dune/stuff/common/type_utils.hh>
 #include <dune/stuff/common/vector.hh>
+#include <dune/stuff/common/math.hh>
 
 #include "container-interface.hh"
 #include "vector-interface-internal.hh"
@@ -125,7 +126,7 @@ public:
   virtual bool valid() const
   {
     for (const auto& val : *this) {
-      if (std::isnan(std::real(val)) || std::isnan(std::imag(val)) || std::isinf(std::abs(val)))
+      if (Common::isnan(val) || Common::isinf(val))
         return false;
     }
     return true;
diff --git a/dune/stuff/la/solver/common.hh b/dune/stuff/la/solver/common.hh
index 1a47adef1..f387e3fce 100644
--- a/dune/stuff/la/solver/common.hh
+++ b/dune/stuff/la/solver/common.hh
@@ -88,7 +88,7 @@ public:
       matrix_.mv(solution, tmp);
       tmp -= rhs;
       const R sup_norm = tmp.sup_norm();
-      if (sup_norm > post_check_solves_system_threshold || std::isnan(sup_norm) || std::isinf(sup_norm))
+      if (sup_norm > post_check_solves_system_threshold || DSC::isnan(sup_norm) || DSC::isinf(sup_norm))
         DUNE_THROW(Exceptions::linear_solver_failed_bc_the_solution_does_not_solve_the_system,
                    "The computed solution does not solve the system (although the dune-common backend "
                        << "reported no error) and you requested checking (see options below)! "
diff --git a/dune/stuff/la/solver/eigen.hh b/dune/stuff/la/solver/eigen.hh
index 43af85e91..a79cc37a6 100644
--- a/dune/stuff/la/solver/eigen.hh
+++ b/dune/stuff/la/solver/eigen.hh
@@ -114,7 +114,7 @@ public:
       for (size_t ii = 0; ii < matrix_.rows(); ++ii) {
         for (size_t jj = 0; jj < matrix_.cols(); ++jj) {
           const S& val = matrix_.backend()(ii, jj);
-          if (std::isnan(std::real(val)) || std::isnan(std::imag(val)) || std::isinf(std::abs(val))) {
+          if (Common::isnan(val) || Common::isinf(val)) {
             std::stringstream msg;
             msg << "Given matrix contains inf or nan and you requested checking (see options below)!\n"
                 << "If you want to disable this check, set 'check_for_inf_nan = 0' in the options.\n\n"
@@ -127,7 +127,7 @@ public:
       }
       for (size_t ii = 0; ii < rhs.size(); ++ii) {
         const S& val = rhs[ii];
-        if (std::isnan(std::real(val)) || std::isnan(std::imag(val)) || std::isinf(std::abs(val))) {
+        if (Common::isnan(val) || Common::isinf(val)) {
           std::stringstream msg;
           msg << "Given rhs contains inf or nan and you requested checking (see options below)!\n"
               << "If you want to disable this check, set 'check_for_inf_nan = 0' in the options.\n\n"
@@ -179,7 +179,7 @@ public:
     if (check_for_inf_nan)
       for (size_t ii = 0; ii < solution.size(); ++ii) {
         const S& val = solution[ii];
-        if (std::isnan(std::real(val)) || std::isnan(std::imag(val)) || std::isinf(std::abs(val))) {
+        if (Common::isnan(val) || Common::isinf(val)) {
           std::stringstream msg;
           msg << "The computed solution contains inf or nan and you requested checking (see options "
               << "below)!\n"
@@ -197,7 +197,7 @@ public:
       auto tmp = rhs.copy();
       tmp.backend() = matrix_.backend() * solution.backend() - rhs.backend();
       const R sup_norm = tmp.sup_norm();
-      if (sup_norm > post_check_solves_system_threshold || std::isnan(sup_norm) || std::isinf(sup_norm)) {
+      if (sup_norm > post_check_solves_system_threshold || DSC::isnan(sup_norm) || DSC::isinf(sup_norm)) {
         std::stringstream msg;
         msg << "The computed solution does not solve the system (although the eigen backend reported "
             << "'Success') and you requested checking (see options below)!\n"
@@ -336,8 +336,8 @@ public:
       typedef typename MatrixType::BackendType::InnerIterator InnerIterator;
       for (EIGEN_size_t ii = 0; ii < matrix_.backend().outerSize(); ++ii) {
         for (InnerIterator it(matrix_.backend(), ii); it; ++it) {
-          if (std::isnan(std::real(it.value())) || std::isnan(std::imag(it.value()))
-              || std::isinf(std::abs(it.value())))
+          if (DSC::isnan(std::real(it.value())) || DSC::isnan(std::imag(it.value()))
+              || DSC::isinf(std::abs(it.value())))
             DUNE_THROW(Exceptions::linear_solver_failed_bc_data_did_not_fulfill_requirements,
                        "Given matrix contains inf or nan and you requested checking (see options below)!\n"
                            << "If you want to disable this check, set 'check_for_inf_nan = 0' in the options.\n\n"
@@ -347,7 +347,7 @@ public:
       }
       for (size_t ii = 0; ii < rhs.size(); ++ii) {
         const S& val = rhs[ii];
-        if (std::isnan(std::real(val)) || std::isnan(std::imag(val)) || std::isinf(std::abs(val)))
+        if (Common::isnan(val) || Common::isinf(val))
           DUNE_THROW(Exceptions::linear_solver_failed_bc_data_did_not_fulfill_requirements,
                      "Given rhs contains inf or nan and you requested checking (see options below)!\n"
                          << "If you want to disable this check, set 'check_for_inf_nan = 0' in the options.\n\n"
@@ -545,7 +545,7 @@ public:
     if (check_for_inf_nan)
       for (size_t ii = 0; ii < solution.size(); ++ii) {
         const S& val = solution[ii];
-        if (std::isnan(std::real(val)) || std::isnan(std::imag(val)) || std::isinf(std::abs(val)))
+        if (Common::isnan(val) || Common::isinf(val))
           DUNE_THROW(Exceptions::linear_solver_failed_bc_data_did_not_fulfill_requirements,
                      "The computed solution contains inf or nan and you requested checking (see options "
                          << "below)!\n"
@@ -559,7 +559,7 @@ public:
       auto tmp = rhs.copy();
       tmp.backend() = matrix_.backend() * solution.backend() - rhs.backend();
       const R sup_norm = tmp.sup_norm();
-      if (sup_norm > post_check_solves_system_threshold || std::isnan(sup_norm) || std::isinf(sup_norm))
+      if (sup_norm > post_check_solves_system_threshold || DSC::isnan(sup_norm) || DSC::isinf(sup_norm))
         DUNE_THROW(Exceptions::linear_solver_failed_bc_the_solution_does_not_solve_the_system,
                    "The computed solution does not solve the system (although the eigen backend reported "
                        << "'Success') and you requested checking (see options below)!\n"
diff --git a/dune/stuff/la/solver/istl.hh b/dune/stuff/la/solver/istl.hh
index cb2226f04..2a48c0d64 100644
--- a/dune/stuff/la/solver/istl.hh
+++ b/dune/stuff/la/solver/istl.hh
@@ -198,7 +198,7 @@ public:
         matrix_.mv(solution, writable_rhs);
         writable_rhs -= rhs;
         const R sup_norm = writable_rhs.sup_norm();
-        if (sup_norm > post_check_solves_system_threshold || std::isnan(sup_norm) || std::isinf(sup_norm))
+        if (sup_norm > post_check_solves_system_threshold || DSC::isnan(sup_norm) || DSC::isinf(sup_norm))
           DUNE_THROW(Exceptions::linear_solver_failed_bc_the_solution_does_not_solve_the_system,
                      "The computed solution does not solve the system (although the dune-istl backend "
                          << "reported no error) and you requested checking (see options below)!\n"
-- 
GitLab