cMHN 1.2
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
8
10{
11 template<class T, class SN, class SR, class F>
12 class Assignable : public View<T, SN, SR, F>
13 {
14 private:
16
17 public:
18 constexpr auto &operator=(Zero<> const)
19 {
20 return *this = zero<F>();
21 }
22
23 constexpr auto &operator=(Unit<> const)
24 {
25 return *this = unit<F>();
26 }
27
28 template<class X, IsTensorish R = RemoveReference<X>>
32 constexpr auto &operator=(X &&rhs)
33 {
35 [this, &rhs](auto const i)
36 {
37 this->self().template core<i>() =
38 forward<X>(rhs).template core<i>();
39 });
40 return this->self();
41 }
42
43 template<class X, IsTensorish R = RemoveReference<X>>
46 IsSame<typename Base::Ranks,
47 typename decltype(round<typename Base::Ranks>(
48 declval<X>()))::Ranks> &&
50 constexpr auto &operator=(X &&rhs)
51 {
52 this->self() = round<typename Base::Ranks>(forward<X>(rhs));
53 return this->self();
54 }
55
56 template<class X>
58 constexpr auto operator+=(X &&rhs)
59 {
60 this->self() = this->self() + forward<X>(rhs);
61 return this->self();
62 }
63
64 template<class X>
66 constexpr auto operator-=(X &&rhs)
67 {
68 this->self() = this->self() - forward<X>(rhs);
69 return this->self();
70 }
71
72 template<class X>
74 constexpr auto applyOnTheLeft(X &&lhs)
75 {
76 this->self() = eval(forward<X>(lhs) * this->self());
77 return this->self();
78 }
79
80 template<class X>
82 constexpr auto applyOnTheRight(X &&rhs)
83 {
84 this->self() = eval(this->self() * forward<X>(rhs));
85 return this->self();
86 }
87
88 template<class X>
90 constexpr auto operator*=(X &&rhs)
91 {
92 return applyOnTheRight(forward<X>(rhs));
93 }
94
95 template<class X>
97 constexpr auto operator/=(X &&rhs)
98 {
99 this->self() = this->self() / forward<X>(rhs);
100 return this->self();
101 }
102
103 protected:
104 ~Assignable() = default;
105 constexpr Assignable(Assignable const &) = default;
106 constexpr Assignable(Assignable &&) = default;
107 constexpr Assignable &operator=(Assignable const &) = delete;
108 constexpr Assignable &operator=(Assignable &&) = delete;
109 constexpr Assignable() = default;
110 };
111}
112#endif // pRC_TENSOR_TRAIN_TENSOR_VIEWS_ASSIGNABLE_H
Definition assignable.hpp:13
constexpr auto & operator=(X &&rhs)
Definition assignable.hpp:32
constexpr Assignable & operator=(Assignable &&)=delete
constexpr auto operator-=(X &&rhs)
Definition assignable.hpp:66
constexpr auto operator+=(X &&rhs)
Definition assignable.hpp:58
constexpr auto applyOnTheRight(X &&rhs)
Definition assignable.hpp:82
constexpr Assignable & operator=(Assignable const &)=delete
constexpr auto & operator=(Unit<> const)
Definition assignable.hpp:23
constexpr auto operator/=(X &&rhs)
Definition assignable.hpp:97
constexpr auto & operator=(Zero<> const)
Definition assignable.hpp:18
constexpr Assignable(Assignable &&)=default
constexpr auto applyOnTheLeft(X &&lhs)
Definition assignable.hpp:74
constexpr Assignable(Assignable const &)=default
constexpr auto operator*=(X &&rhs)
Definition assignable.hpp:90
Definition declarations.hpp:21
Definition concepts.hpp:40
Definition concepts.hpp:31
Definition concepts.hpp:28
int i
Definition gmock-matchers-comparisons_test.cc:603
Definition declarations.hpp:19
static constexpr auto unit()
Definition unit.hpp:13
static constexpr auto range(F &&f, Xs &&...args)
Definition range.hpp:18
static constexpr auto zero()
Definition zero.hpp:12
static constexpr auto round(T const &a)
Definition round.hpp:11
static constexpr decltype(auto) eval(X &&a)
Definition eval.hpp:12
Definition unit.hpp:11
Definition zero.hpp:11