pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
relative_error.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_VALUE_FUNCTIONS_RELATIVE_ERROR_H
4#define pRC_CORE_VALUE_FUNCTIONS_RELATIVE_ERROR_H
5
13
14namespace pRC
15{
35 template<class XA, class XB, class RA = RemoveReference<XA>,
36 class RB = RemoveReference<XB>, If<IsFloat<typename RA::Value>> = 0,
37 If<IsFloat<typename RB::Value>> = 0,
38 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
39 If<IsInvocable<Norm<>, XA>> = 0,
40 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
41 ResultOf<Norm<>, XA>>> = 0>
42 static inline constexpr auto relativeError(XA &&a, XB &&b)
43 {
44 return absoluteError(a, b) / norm(a);
45 }
46
66 template<class XA, class XB, class RA = RemoveReference<XA>,
67 class RB = RemoveReference<XB>, If<IsFloat<typename RA::Value>> = 0,
68 If<Not<IsFloat<typename RB::Value>>> = 0,
69 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
70 If<IsInvocable<Norm<>, XA>> = 0,
71 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
72 ResultOf<Norm<>, XA>>> = 0>
73 static inline constexpr auto relativeError(XA &&a, XB &&b)
74 {
75 return relativeError(a, cast<Float<>>(b));
76 }
77
97 template<class XA, class XB, class RA = RemoveReference<XA>,
98 class RB = RemoveReference<XB>,
99 If<Not<IsFloat<typename RA::Value>>> = 0,
100 If<IsFloat<typename RB::Value>> = 0,
101 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
102 If<IsInvocable<Norm<>, XA>> = 0,
103 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
104 ResultOf<Norm<>, XA>>> = 0>
105 static inline constexpr auto relativeError(XA &&a, XB &&b)
106 {
107 return relativeError(cast<Float<>>(a), b);
108 }
109
129 template<class XA, class XB, class RA = RemoveReference<XA>,
130 class RB = RemoveReference<XB>,
131 If<Not<IsFloat<typename RA::Value>>> = 0,
132 If<Not<IsFloat<typename RB::Value>>> = 0,
133 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
134 If<IsInvocable<Norm<>, XA>> = 0,
135 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
136 ResultOf<Norm<>, XA>>> = 0>
137 static inline constexpr auto relativeError(XA &&a, XB &&b)
138 {
139 return relativeError(cast<Float<>>(a), cast<Float<>>(b));
140 }
141}
142#endif // pRC_CORE_VALUE_FUNCTIONS_RELATIVE_ERROR_H
Definition cholesky.hpp:18
static constexpr auto absoluteError(XA &&a, XB &&b)
Calculates the absolute error of two pRC objects.
Definition absolute_error.hpp:29
static constexpr auto relativeError(XA &&a, XB &&b)
Calculates the relative error of a pRC object from another pRC object.
Definition relative_error.hpp:42
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto cast(Complex< T > const &a)
Definition cast.hpp:13
static constexpr auto norm(Complex< T > const &a)
Definition norm.hpp:11