cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
bool.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_BOOL_H
4#define pRC_CORE_TENSOR_BOOL_H
5
17
18namespace pRC
19{
20 template<Size... Ns>
21 class Tensor<Bool, Ns...>
22 {
23 static_assert((Ns * ... * 1) <= NumericLimits<Size>::max() &&
25
26 public:
27 using Type = Bool;
28 template<class C>
29 using ChangeType = Tensor<C, Ns...>;
30
32
33 using Sizes = pRC::Sizes<Ns...>;
34 template<Size... Ss>
35 using ChangeSizes = Tensor<Bool, Ss...>;
36
37 using Dimension = typename Sizes::Dimension;
38
39 template<class E = typename Sizes::IsLinearizable, If<E> = 0>
40 static constexpr auto size()
41 {
42 return Sizes::size();
43 }
44
45 static constexpr auto size(Index const dimension)
46 {
47 return Sizes::size(dimension);
48 }
49
50 template<class X, class... Is, If<IsConstructible<Bool, X>> = 0,
52 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
53 static constexpr auto Single(X &&value, Is const... indices)
54 {
55 return Single(forward<X>(value), Subscripts(indices...));
56 }
57
58 template<class X, If<IsConstructible<Bool, X>> = 0>
59 static constexpr auto Single(X &&value, Subscripts const &subscripts)
60 {
61 return TensorViews::Single<Bool, Sizes>(forward<X>(value),
63 }
64
65 public:
66 ~Tensor() = default;
67 constexpr Tensor(Tensor const &) = default;
68 constexpr Tensor(Tensor &&) = default;
69 constexpr Tensor &operator=(Tensor const &) & = default;
70 constexpr Tensor &operator=(Tensor &&) & = default;
71 constexpr Tensor() = default;
72
73 template<class X,
75 constexpr Tensor(X &&other)
76 {
77 *this = forward<X>(other);
78 }
79
80 template<class X,
82 constexpr auto &operator=(X &&rhs) &
83 {
84 view(*this) = forward<X>(rhs);
85 return *this;
86 }
87
88 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
89 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
90 constexpr decltype(auto) operator()(Is const... indices) &&
91 {
92 return move(mData)(indices...);
93 }
94
95 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
96 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
97 constexpr decltype(auto) operator()(Is const... indices) const &&
98 {
99 return move(mData)(indices...);
100 }
101
102 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
103 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
104 constexpr decltype(auto) operator()(Is const... indices) &
105 {
106 return mData(indices...);
107 }
108
109 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
110 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
111 constexpr decltype(auto) operator()(Is const... indices) const &
112 {
113 return mData(indices...);
114 }
115
116 constexpr decltype(auto) operator()(Subscripts const &subscripts) &&
117 {
118 return move(mData)(subscripts);
119 }
120
121 constexpr decltype(auto) operator()(
122 Subscripts const &subscripts) const &&
123 {
124 return move(mData)(subscripts);
125 }
126
127 constexpr decltype(auto) operator()(Subscripts const &subscripts) &
128 {
129 return mData(subscripts);
130 }
131
132 constexpr decltype(auto) operator()(
133 Subscripts const &subscripts) const &
134 {
135 return mData(subscripts);
136 }
137
138 constexpr decltype(auto) operator[](Index const index) &&
139 {
140 return move(mData)[index];
141 }
142
143 constexpr decltype(auto) operator[](Index const index) const &&
144 {
145 return move(mData)[index];
146 }
147
148 constexpr decltype(auto) operator[](Index const index) &
149 {
150 return mData[index];
151 }
152
153 constexpr decltype(auto) operator[](Index const index) const &
154 {
155 return mData[index];
156 }
157
158 explicit constexpr operator Bool() const
159 {
160 return reduce<LogicalAnd>(*this)();
161 }
162
163 private:
164 BEGIN_IGNORE_DIAGNOSTIC_GCC("-Wpedantic")
165 Array<Bool, Ns...> mData;
167 };
168}
169#endif // pRC_CORE_TENSOR_BOOL_H
Definition sequence.hpp:56
static constexpr auto size()
Definition sequence.hpp:88
Constant< Size, sizeof...(Ns)> Dimension
Definition sequence.hpp:74
Constant< Bool, linearizable()> IsLinearizable
Definition sequence.hpp:75
Definition subscripts.hpp:20
Definition single.hpp:13
constexpr Tensor & operator=(Tensor &&) &=default
static constexpr auto size(Index const dimension)
Definition bool.hpp:45
constexpr Tensor(Tensor &&)=default
static constexpr auto Single(X &&value, Subscripts const &subscripts)
Definition bool.hpp:59
constexpr Tensor & operator=(Tensor const &) &=default
typename Sizes::Dimension Dimension
Definition bool.hpp:37
constexpr Tensor()=default
constexpr Tensor(X &&other)
Definition bool.hpp:75
static constexpr auto Single(X &&value, Is const ... indices)
Definition bool.hpp:53
static constexpr auto size()
Definition bool.hpp:40
constexpr auto & operator=(X &&rhs) &
Definition bool.hpp:82
constexpr decltype(auto) operator()(Is const ... indices) const &
Definition bool.hpp:111
Bool Type
Definition bool.hpp:27
constexpr decltype(auto) operator()(Is const ... indices) &
Definition bool.hpp:104
constexpr decltype(auto) operator()(Is const ... indices) &&
Definition bool.hpp:90
constexpr decltype(auto) operator()(Is const ... indices) const &&
Definition bool.hpp:97
constexpr Tensor(Tensor const &)=default
Definition tensor.hpp:28
static constexpr auto Single(X &&value, Is const ... indices)
Definition tensor.hpp:78
pRC::Subscripts< Ns... > Subscripts
Definition tensor.hpp:39
typename Sizes::Dimension Dimension
Definition tensor.hpp:45
Definition cholesky.hpp:18
bool Bool
Definition type_traits.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
std::size_t Size
Definition type_traits.hpp:20
static constexpr X view(X &&a)
Definition view.hpp:12
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
Conditional< IsSatisfied<((Ns *... *1) *sizeof(T) > cHugepageSizeByte)>, HeapArray< T, Ns... >, StackArray< T, Ns... > > Array
Definition type_traits.hpp:58
#define BEGIN_IGNORE_DIAGNOSTIC_GCC(warning)
Definition pragma.hpp:42
#define END_IGNORE_DIAGNOSTIC_GCC
Definition pragma.hpp:43
Definition limits.hpp:13