Commit a11f6d40 by Müller, Felix

fixed min/max bug in FieldMatVec

parent d032b2e5
 #pragma once #pragma once #include #include #include #include #include #include #include ... @@ -96,21 +97,19 @@ namespace AMDiS ... @@ -96,21 +97,19 @@ namespace AMDiS namespace Impl namespace Impl { { template template T accumulate(FieldVector const& x, Operation op) T accumulate(FieldVector const& x, T init, Operation op) { { T result = 0; for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i) result = op(result, x[i]); init = op(init, x[i]); return result; return init; } } template template T accumulate(FieldMatrix const& x, Operation op) T accumulate(FieldMatrix const& x, T init, Operation op) { { T result = 0; for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i) result = op(result, x[0][i]); init = op(init, x[0][i]); return result; return init; } } } // end namespace Impl } // end namespace Impl ... @@ -119,13 +118,13 @@ namespace AMDiS ... @@ -119,13 +118,13 @@ namespace AMDiS template template T sum(FieldVector const& x) T sum(FieldVector const& x) { { return Impl::accumulate(x, Operation::Plus{}); return Impl::accumulate(x, T(0), Operation::Plus{}); } } template template T sum(FieldMatrix const& x) T sum(FieldMatrix const& x) { { return Impl::accumulate(x, Operation::Plus{}); return Impl::accumulate(x, T(0), Operation::Plus{}); } } ... @@ -134,66 +133,66 @@ namespace AMDiS ... @@ -134,66 +133,66 @@ namespace AMDiS auto unary_dot(FieldVector const& x) auto unary_dot(FieldVector const& x) { { auto op = [](auto const& a, auto const& b) { return a + Math::sqr(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + Math::sqr(std::abs(b)); }; return Impl::accumulate(x, op); return Impl::accumulate(x, T(0), op); } } template template auto unary_dot(FieldMatrix const& x) auto unary_dot(FieldMatrix const& x) { { auto op = [](auto const& a, auto const& b) { return a + Math::sqr(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + Math::sqr(std::abs(b)); }; return Impl::accumulate(x, op); return Impl::accumulate(x, T(0), op); } } /// Maximum over all vector entries /// Maximum over all vector entries template template auto max(FieldVector const& x) auto max(FieldVector const& x) { { return Impl::accumulate(x, Operation::Max{}); return Impl::accumulate(x, std::numeric_limits::lowest(), Operation::Max{}); } } template template auto max(FieldMatrix const& x) auto max(FieldMatrix const& x) { { return Impl::accumulate(x, Operation::Max{}); return Impl::accumulate(x, std::numeric_limits::lowest(), Operation::Max{}); } } /// Minimum over all vector entries /// Minimum over all vector entries template template auto min(FieldVector const& x) auto min(FieldVector const& x) { { return Impl::accumulate(x, Operation::Min{}); return Impl::accumulate(x, std::numeric_limits::max(), Operation::Min{}); } } template template auto min(FieldMatrix const& x) auto min(FieldMatrix const& x) { { return Impl::accumulate(x, Operation::Min{}); return Impl::accumulate(x, std::numeric_limits::max(), Operation::Min{}); } } /// Maximum of the absolute values of vector entries /// Maximum of the absolute values of vector entries template template auto abs_max(FieldVector const& x) auto abs_max(FieldVector const& x) { { return Impl::accumulate(x, Operation::AbsMax{}); return Impl::accumulate(x, T(0), Operation::AbsMax{}); } } template template auto abs_max(FieldMatrix const& x) auto abs_max(FieldMatrix const& x) { { return Impl::accumulate(x, Operation::AbsMax{}); return Impl::accumulate(x, T(0), Operation::AbsMax{}); } } /// Minimum of the absolute values of vector entries /// Minimum of the absolute values of vector entries template template auto abs_min(FieldVector const& x) auto abs_min(FieldVector const& x) { { return Impl::accumulate(x, Operation::AbsMin{}); return Impl::accumulate(x, std::numeric_limits::max(), Operation::AbsMin{}); } } template template auto abs_min(FieldMatrix const& x) auto abs_min(FieldMatrix const& x) { { return Impl::accumulate(x, Operation::AbsMin{}); return Impl::accumulate(x, std::numeric_limits::max(), Operation::AbsMin{}); } } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- ... @@ -205,14 +204,14 @@ namespace AMDiS ... @@ -205,14 +204,14 @@ namespace AMDiS auto one_norm(FieldVector const& x) auto one_norm(FieldVector const& x) { { auto op = [](auto const& a, auto const& b) { return a + std::abs(b); }; auto op = [](auto const& a, auto const& b) { return a + std::abs(b); }; return Impl::accumulate(x, op); return Impl::accumulate(x, T(0), op); } } template template auto one_norm(FieldMatrix const& x) auto one_norm(FieldMatrix const& x) { { auto op = [](auto const& a, auto const& b) { return a + std::abs(b); }; auto op = [](auto const& a, auto const& b) { return a + std::abs(b); }; return Impl::accumulate(x, op); return Impl::accumulate(x, T(0), op); } } /** \ingroup vector_norms /** \ingroup vector_norms ... @@ -237,14 +236,14 @@ namespace AMDiS ... @@ -237,14 +236,14 @@ namespace AMDiS auto p_norm(FieldVector const& x) auto p_norm(FieldVector const& x) { { auto op = [](auto const& a, auto const& b) { return a + Math::pow

(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + Math::pow

(std::abs(b)); }; return std::pow( Impl::accumulate(x, op), 1.0/p ); return std::pow( Impl::accumulate(x, T(0), op), 1.0/p ); } } template template auto p_norm(FieldMatrix const& x) auto p_norm(FieldMatrix const& x) { { auto op = [](auto const& a, auto const& b) { return a + Math::pow

(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + Math::pow

(std::abs(b)); }; return std::pow( Impl::accumulate(x, op), 1.0/p ); return std::pow( Impl::accumulate(x, T(0), op), 1.0/p ); } } /** \ingroup vector_norms /** \ingroup vector_norms ... ...