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_TENSOR_VIEWS_ASSIGNABLE_H
4#define pRC_TENSOR_TRAIN_TENSOR_VIEWS_ASSIGNABLE_H
5
18
20{
21 template<class T, Size... Ns, Size... Rs, class F>
22 class Assignable<T, Sizes<Ns...>, Sizes<Rs...>, F>
23 : public View<T, Sizes<Ns...>, Sizes<Rs...>, F>
24 {
25 private:
26 using Base = View<T, Sizes<Ns...>, Sizes<Rs...>, F>;
27
28 public:
29 constexpr auto &operator=(Zero<> const)
30 {
31 return *this = zero<F>();
32 }
33
34 constexpr auto &operator=(Unit<> const)
35 {
36 return *this = unit<F>();
37 }
38
39 template<class X, class R = RemoveReference<X>, If<IsTensorish<R>> = 0,
40 If<IsSame<typename Base::Sizes, typename R::Sizes>> = 0,
41 If<IsSame<typename Base::Ranks, typename R::Ranks>> = 0,
42 If<IsConvertible<typename R::Type, T>> = 0>
43 constexpr auto &operator=(X &&rhs)
44 {
46 [this, &rhs](auto const i)
47 {
48 this->self().template core<i>() =
49 forward<X>(rhs).template core<i>();
50 });
51 return this->self();
52 }
53
54 template<class X, class R = RemoveReference<X>, If<IsTensorish<R>> = 0,
55 If<IsSame<typename Base::Sizes, typename R::Sizes>> = 0,
56 If<Not<IsSame<typename Base::Ranks, typename R::Ranks>>> = 0,
57 If<IsSame<typename Base::Ranks,
58 typename decltype(round<Rs...>(declval<X>()))::Ranks>> = 0,
59 If<IsConvertible<typename R::Type, T>> = 0>
60 constexpr auto &operator=(X &&rhs)
61 {
62 this->self() = round<Rs...>(forward<X>(rhs));
63 return this->self();
64 }
65
66 template<class X, If<IsInvocable<Add, F, X>> = 0>
67 constexpr auto operator+=(X &&rhs)
68 {
69 this->self() = this->self() + forward<X>(rhs);
70 return this->self();
71 }
72
73 template<class X, If<IsInvocable<Sub, F, X>> = 0>
74 constexpr auto operator-=(X &&rhs)
75 {
76 this->self() = this->self() - forward<X>(rhs);
77 return this->self();
78 }
79
80 template<class X, If<IsInvocable<Mul, X, F>> = 0>
81 constexpr auto applyOnTheLeft(X &&lhs)
82 {
83 this->self() = eval(forward<X>(lhs) * this->self());
84 return this->self();
85 }
86
87 template<class X, If<IsInvocable<Mul, F, X>> = 0>
88 constexpr auto applyOnTheRight(X &&rhs)
89 {
90 this->self() = eval(this->self() * forward<X>(rhs));
91 return this->self();
92 }
93
94 template<class X, If<IsInvocable<Mul, F, X>> = 0>
95 constexpr auto operator*=(X &&rhs)
96 {
97 return applyOnTheRight(forward<X>(rhs));
98 }
99
100 template<class X, If<IsInvocable<Div, F, X>> = 0>
101 constexpr auto operator/=(X &&rhs)
102 {
103 this->self() = this->self() / forward<X>(rhs);
104 return this->self();
105 }
106
107 protected:
108 ~Assignable() = default;
109 constexpr Assignable(Assignable const &) = default;
110 constexpr Assignable(Assignable &&) = default;
111 constexpr Assignable &operator=(Assignable const &) = delete;
112 constexpr Assignable &operator=(Assignable &&) = delete;
113 constexpr Assignable() = default;
114 };
115}
116#endif // pRC_TENSOR_TRAIN_TENSOR_VIEWS_ASSIGNABLE_H
Definition sequence.hpp:56
constexpr auto operator*=(X &&rhs)
Definition assignable.hpp:95
constexpr auto applyOnTheRight(X &&rhs)
Definition assignable.hpp:88
constexpr auto & operator=(X &&rhs)
Definition assignable.hpp:60
constexpr auto operator/=(X &&rhs)
Definition assignable.hpp:101
constexpr auto & operator=(Unit<> const)
Definition assignable.hpp:34
constexpr auto applyOnTheLeft(X &&lhs)
Definition assignable.hpp:81
constexpr auto operator-=(X &&rhs)
Definition assignable.hpp:74
constexpr auto operator+=(X &&rhs)
Definition assignable.hpp:67
constexpr auto & operator=(Zero<> const)
Definition assignable.hpp:29
constexpr auto & operator=(X &&rhs)
Definition assignable.hpp:43
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:265
Definition type_traits.hpp:268