pRC
multi-purpose Tensor Train library for C++
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{
35 template<class XA, class XB, class RA = RemoveReference<XA>,
36 class RB = RemoveReference<XB>,
37 class TT = Common<typename RA::Value, typename RB::Value>,
38 class T = Common<typename RA::Value, typename RB::Value, TT>,
39 If<IsValue<TT>> = 0, If<IsInvocable<AbsoluteError, XA, XB>> = 0,
40 If<IsInvocable<Norm<>, XA>> = 0, If<IsInvocable<Norm<>, XB>> = 0,
41 If<IsConstructible<T, ResultOf<AbsoluteError, XA, XB>>> = 0,
42 If<IsConstructible<T, ResultOf<Norm<>, XA>>> = 0,
43 If<IsConstructible<T, ResultOf<Norm<>, XB>>> = 0>
44 static inline constexpr auto isApprox(XA &&a, XB &&b,
45 TT const &tolerance = NumericLimits<TT>::tolerance())
46 {
47 auto const absError = static_cast<T>(absoluteError(a, b));
48
49 auto const normA = static_cast<T>(norm(a));
50 auto const normB = static_cast<T>(norm(b));
51
52 return absError <= tolerance * min(normA, normB);
53 }
54}
55#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 absoluteError(XA &&a, XB &&b)
Calculates the absolute error of two pRC objects.
Definition absolute_error.hpp:29
static constexpr auto isApprox(XA &&a, XB &&b, TT const &tolerance=NumericLimits< TT >::tolerance())
Checks if two pRC objects agree up to a given tolerance.
Definition is_approx.hpp:44
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto norm(Complex< T > const &a)
Definition norm.hpp:11
Definition limits.hpp:13