FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
max_rel_diff_dense_generic.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8#ifndef KERNEL_LAFEM_ARCH_MAX_REL_DIFF_DENSE_HPP
9#error "Do not include this implementation-only header file directly!"
10#endif
11
12#include <kernel/util/math.hpp>
13
14namespace FEAT::LAFEM::Arch
15{
16 template <typename DT_>
17 DT_ MaxRelDiffDense::exec_generic_impl(const DT_ * const x, const DT_ * const y, const Index size)
18 {
19 DT_ r(0);
20 bool has_nan = false;
21 bool has_inf = false;
22 for (Index i(0) ; i < size ; ++i)
23 {
24 has_nan = has_nan || Math::isnan(x[i]) || Math::isnan(y[i]);
25 has_inf = has_inf || Math::isinf(x[i]) || Math::isinf(y[i]);
26 r = Math::max(r, Math::abs(x[i] - y[i]) / (Math::abs(x[i]) + Math::abs(y[i]) + DT_(1)));
27 }
28
29 // if we found a NaN or an infinity, we'll return a NaN here
30 return (has_nan || has_inf ? Math::nan<DT_>() : r);
31 }
32} // namespace FEAT::LAFEM::Arch
bool isinf(T_ x)
Checks whether a value is infinite.
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
bool isnan(T_ x)
Checks whether a value is Not-A-Number.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
std::uint64_t Index
Index data type.