cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
scale.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_TENSOR_TRAIN_COMMON_FUNCTIONS_SCALE_H
4#define pRC_TENSOR_TRAIN_COMMON_FUNCTIONS_SCALE_H
5
15
16namespace pRC
17{
18 template<class XA, class XB, class RA = RemoveReference<XA>,
19 class RB = RemoveReference<XB>,
20 If<Any<TensorTrain::IsTensorish<RA>, TensorTrain::IsOperatorish<RA>>> =
21 0,
22 If<IsInvocable<View, XA>> = 0, If<Any<IsValue<RB>, IsComplex<RB>>> = 0,
23 If<IsInvocable<Mul, typename RA::Type, RB const &>> = 0>
24 static inline constexpr auto operator*(XA &&a, XB &&b)
25 {
26 return enumerate(
27 [lambda = pow(abs(b), rcp(unit<RB>(typename RA::Dimension()))),
28 sgn = sign(b)]<Index C>(auto &&a)
29 {
30 if constexpr(C == 0)
31 {
32 return forward<decltype(a)>(a) * sgn * lambda;
33 }
34 else
35 {
36 return forward<decltype(a)>(a) * lambda;
37 }
38 },
39 forward<XA>(a));
40 }
41
42 template<class XA, class XB, class RA = RemoveReference<XA>,
43 class RB = RemoveReference<XB>, If<Any<IsValue<RA>, IsComplex<RA>>> = 0,
44 If<Any<TensorTrain::IsTensorish<RB>, TensorTrain::IsOperatorish<RB>>> =
45 0,
46 If<IsInvocable<View, XB>> = 0,
47 If<IsInvocable<Mul, RA const &, typename RB::Type>> = 0>
48 static inline constexpr auto operator*(XA &&a, XB &&b)
49 {
50 return forward<XB>(b) * forward<XA>(a);
51 }
52
53 template<class XA, class XB, class RA = RemoveReference<XA>,
54 class RB = RemoveReference<XB>,
55 If<Any<TensorTrain::IsTensorish<RA>, TensorTrain::IsOperatorish<RA>>> =
56 0,
57 If<IsInvocable<View, XA>> = 0, If<Any<IsValue<RB>, IsComplex<RB>>> = 0,
58 If<IsInvocable<Div, typename RA::Type, RB const &>> = 0>
59 static inline constexpr auto operator/(XA &&a, XB &&b)
60 {
62
63 return forward<XA>(a) * rcp(cast<typename T::Value>(forward<XB>(b)));
64 }
65
66 template<class XA, class XB, class RA = RemoveReference<XA>,
67 class RB = RemoveReference<XB>,
68 If<Any<TensorTrain::IsTensorish<RA>, TensorTrain::IsOperatorish<RA>>> =
69 0,
70 If<Not<IsInvocable<View, XA>>> = 0,
71 If<Any<IsValue<RB>, IsComplex<RB>>> = 0,
72 If<IsInvocable<Mul, XA &, RB const &>> = 0>
73 static inline constexpr auto operator*(XA &&a, XB &&b)
74 {
75 return eval(a * forward<XB>(b));
76 }
77
78 template<class XA, class XB, class RA = RemoveReference<XA>,
79 class RB = RemoveReference<XB>, If<Any<IsValue<RA>, IsComplex<RA>>> = 0,
80 If<Any<TensorTrain::IsTensorish<RB>, TensorTrain::IsOperatorish<RB>>> =
81 0,
82 If<Not<IsInvocable<View, XB>>> = 0,
83 If<IsInvocable<Mul, RA const &, XB &>> = 0>
84 static inline constexpr auto operator*(XA &&a, XB &&b)
85 {
86 return eval(forward<XA>(a) * b);
87 }
88
89 template<class XA, class XB, class RA = RemoveReference<XA>,
90 class RB = RemoveReference<XB>,
91 If<Any<TensorTrain::IsTensorish<RA>, TensorTrain::IsOperatorish<RA>>> =
92 0,
93 If<Not<IsInvocable<View, XA>>> = 0,
94 If<Any<IsValue<RB>, IsComplex<RB>>> = 0,
95 If<IsInvocable<Div, XA &, RB const &>> = 0>
96 static inline constexpr auto operator/(XA &&a, XB &&b)
97 {
98 return eval(a / forward<XB>(b));
99 }
100
101 template<class XA, class XB, class RA = RemoveReference<XA>,
102 class RB = RemoveReference<XB>,
103 If<Any<TensorTrain::IsTensorish<RA>, TensorTrain::IsOperatorish<RA>>> =
104 0,
105 If<IsTensorish<RB>> = 0,
106 If<IsInvocable<Mul, XA, typename RB::Type>> = 0>
107 static inline constexpr auto operator*(XA &&a, XB &&b)
108 {
109 return forward<XA>(a) * forward<XB>(b)();
110 }
111
112 template<class XA, class XB, class RA = RemoveReference<XA>,
113 class RB = RemoveReference<XB>, If<IsTensorish<RA>> = 0,
114 If<Any<TensorTrain::IsTensorish<RB>, TensorTrain::IsOperatorish<RB>>> =
115 0,
116 If<IsInvocable<Mul, typename RA::Type, XB>> = 0>
117 static inline constexpr auto operator*(XA &&a, XB &&b)
118 {
119 return forward<XA>(a)() * forward<XB>(b);
120 }
121
122 template<class XA, class XB, class RA = RemoveReference<XA>,
123 class RB = RemoveReference<XB>,
124 If<Any<TensorTrain::IsTensorish<RA>, TensorTrain::IsOperatorish<RA>>> =
125 0,
126 If<IsTensorish<RB>> = 0,
127 If<IsInvocable<Div, XA, typename RB::Type>> = 0>
128 static inline constexpr auto operator/(XA &&a, XB &&b)
129 {
130 return forward<XA>(a) / forward<XB>(b)();
131 }
132}
133#endif // pRC_TENSOR_TRAIN_COMMON_FUNCTIONS_SCALE_H
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
static constexpr auto rcp(Complex< T > const &b)
Definition rcp.hpp:13
std::invoke_result_t< F, Args... > ResultOf
Definition type_traits.hpp:140
static constexpr auto pow(Complex< X > const &x, Complex< Y > const &y)
Definition pow.hpp:13
static constexpr auto operator*(JacobiRotation< TA > const &a, JacobiRotation< TB > const &b)
Definition jacobi_rotation.hpp:311
static constexpr auto sign(Complex< T > const &a)
Definition sign.hpp:13
static constexpr auto operator/(Sequence< T, As... > const, Sequence< T, Bs... > const)
Definition sequence.hpp:169
static constexpr auto abs(Complex< T > const &a)
Definition abs.hpp:12
static constexpr auto enumerate(F &&f, Xs &&...args)
Definition enumerate.hpp:20