cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
is_approx.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_VALUE_FUNCTIONS_IS_APPROX_H
4#define pRC_CORE_VALUE_FUNCTIONS_IS_APPROX_H
5
12
13namespace pRC
14{
15 template<class XA, class XB, class RA = RemoveReference<XA>,
16 class RB = RemoveReference<XB>,
17 class TT = Common<typename RA::Value, typename RB::Value>,
18 class T = Common<typename RA::Value, typename RB::Value, TT>,
19 If<IsValue<TT>> = 0, If<IsInvocable<AbsoluteError, XA, XB>> = 0,
20 If<IsInvocable<Norm<>, XA>> = 0, If<IsInvocable<Norm<>, XB>> = 0,
21 If<IsConstructible<T, ResultOf<AbsoluteError, XA, XB>>> = 0,
22 If<IsConstructible<T, ResultOf<Norm<>, XA>>> = 0,
23 If<IsConstructible<T, ResultOf<Norm<>, XB>>> = 0>
24 static inline constexpr auto isApprox(XA &&a, XB &&b,
25 TT const &tolerance = NumericLimits<TT>::tolerance())
26 {
27 auto const absError = static_cast<T>(absoluteError(a, b));
28
29 auto const normA = static_cast<T>(norm(a));
30 auto const normB = static_cast<T>(norm(b));
31
32 return absError <= tolerance * min(normA, normB);
33 }
34}
35#endif // pRC_CORE_VALUE_FUNCTIONS_IS_APPROX_H
Definition cholesky.hpp:18
static constexpr X min(X &&a)
Definition min.hpp:13
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static constexpr auto absoluteError(XA &&a, XB &&b)
Definition absolute_error.hpp:18
static constexpr auto isApprox(XA &&a, XB &&b, TT const &tolerance=NumericLimits< TT >::tolerance())
Definition is_approx.hpp:24
static constexpr auto norm(Complex< T > const &a)
Definition norm.hpp:11
Definition limits.hpp:13