cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
assignable.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_TENSOR_TRAIN_OPERATOR_VIEWS_ASSIGNABLE_H
4#define pRC_TENSOR_TRAIN_OPERATOR_VIEWS_ASSIGNABLE_H
5
19
21{
22 template<class T, Size... Ms, Size... Ns, Size... Rs, class F>
23 class Assignable<T, Sizes<Ms...>, Sizes<Ns...>, Sizes<Rs...>, F>
24 : public View<T, Sizes<Ms...>, Sizes<Ns...>, Sizes<Rs...>, F>
25 {
26 private:
27 using Base = View<T, Sizes<Ms...>, Sizes<Ns...>, Sizes<Rs...>, F>;
28
29 public:
30 constexpr auto &operator=(Zero<> const)
31 {
32 return *this = zero<F>();
33 }
34
35 constexpr auto &operator=(Unit<> const)
36 {
37 return *this = unit<F>();
38 }
39
40 constexpr auto &operator=(Identity<> const)
41 {
42 return *this = identity<F>();
43 }
44
45 template<class X, class R = RemoveReference<X>,
46 If<IsOperatorish<R>> = 0,
47 If<IsSame<typename Base::Sizes, typename R::Sizes>> = 0,
48 If<IsSame<typename Base::Ranks, typename R::Ranks>> = 0,
49 If<IsConvertible<typename R::Type, T>> = 0>
50 constexpr auto &operator=(X &&rhs)
51 {
53 [this, &rhs](auto const i)
54 {
55 this->self().template core<i>() =
56 forward<X>(rhs).template core<i>();
57 });
58 return this->self();
59 }
60
61 template<class X, class R = RemoveReference<X>,
62 If<IsOperatorish<R>> = 0,
63 If<IsSame<typename Base::Sizes, typename R::Sizes>> = 0,
64 If<Not<IsSame<typename Base::Ranks, typename R::Ranks>>> = 0,
65 If<IsSame<typename Base::Ranks,
66 typename decltype(round<Rs...>(declval<X>()))::Ranks>> = 0,
67 If<IsConvertible<typename R::Type, T>> = 0>
68 constexpr auto &operator=(X &&rhs)
69 {
70 this->self() = round<Rs...>(forward<X>(rhs));
71 return this->self();
72 }
73
74 template<class X, If<IsInvocable<Add, F, X>> = 0>
75 constexpr auto operator+=(X &&rhs)
76 {
77 this->self() = this->self() + forward<X>(rhs);
78 return this->self();
79 }
80
81 template<class X, If<IsInvocable<Sub, F, X>> = 0>
82 constexpr auto operator-=(X &&rhs)
83 {
84 this->self() = this->self() - forward<X>(rhs);
85 return this->self();
86 }
87
88 template<class X, If<IsInvocable<Mul, X, F>> = 0>
89 constexpr auto applyOnTheLeft(X &&lhs)
90 {
91 this->self() = eval(forward<X>(lhs) * this->self());
92 return this->self();
93 }
94
95 template<class X, If<IsInvocable<Mul, F, X>> = 0>
96 constexpr auto applyOnTheRight(X &&rhs)
97 {
98 this->self() = eval(this->self() * forward<X>(rhs));
99 return this->self();
100 }
101
102 template<class X, If<IsInvocable<Mul, F, X>> = 0>
103 constexpr auto operator*=(X &&rhs)
104 {
105 return applyOnTheRight(forward<X>(rhs));
106 }
107
108 template<class X, If<IsInvocable<Div, F, X>> = 0>
109 constexpr auto operator/=(X &&rhs)
110 {
111 this->self() = this->self() / forward<X>(rhs);
112 return this->self();
113 }
114
115 protected:
116 ~Assignable() = default;
117 constexpr Assignable(Assignable const &) = default;
118 constexpr Assignable(Assignable &&) = default;
119 constexpr Assignable &operator=(Assignable const &) = delete;
120 constexpr Assignable &operator=(Assignable &&) = delete;
121 constexpr Assignable() = default;
122 };
123}
124#endif // pRC_TENSOR_TRAIN_OPERATOR_VIEWS_ASSIGNABLE_H
Definition sequence.hpp:56
Definition type_traits.hpp:40
Definition type_traits.hpp:37
pRC::Float<> T
Definition externs_nonTT.hpp:1
Definition type_traits.hpp:35
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
std::size_t Size
Definition type_traits.hpp:20
static constexpr auto range(F &&f, Xs &&...args)
Definition range.hpp:16
static constexpr auto round(Complex< T > const &a)
Definition round.hpp:12
Definition type_traits.hpp:262
Definition type_traits.hpp:265
Definition type_traits.hpp:268