pRC
multi-purpose Tensor Train library for C++
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{
31 template<Size... Ns>
32 class Tensor<Bool, Ns...>
33 {
34 static_assert((Ns * ... * 1) <= NumericLimits<Size>::max() &&
36
37 public:
38 using Type = Bool;
39 template<class C>
40 using ChangeType = Tensor<C, Ns...>;
41
43
44 using Sizes = pRC::Sizes<Ns...>;
45 template<Size... Ss>
46 using ChangeSizes = Tensor<Bool, Ss...>;
47
48 using Dimension = typename Sizes::Dimension;
49
53 template<class E = typename Sizes::IsLinearizable, If<E> = 0>
54 static constexpr auto size()
55 {
56 return Sizes::size();
57 }
58
65 static constexpr auto size(Index const dimension)
66 {
67 return Sizes::size(dimension);
68 }
69
87 template<class X, class... Is, If<IsConstructible<Bool, X>> = 0,
89 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
90 static constexpr auto Single(X &&value, Is const... indices)
91 {
92 return Single(forward<X>(value), Subscripts(indices...));
93 }
94
109 template<class X, If<IsConstructible<Bool, X>> = 0>
110 static constexpr auto Single(X &&value, Subscripts const &subscripts)
111 {
113 subscripts);
114 }
115
116 public:
117 ~Tensor() = default;
118 constexpr Tensor(Tensor const &) = default;
119 constexpr Tensor(Tensor &&) = default;
120 constexpr Tensor &operator=(Tensor const &) & = default;
121 constexpr Tensor &operator=(Tensor &&) & = default;
122 constexpr Tensor() = default;
123
131 template<class X,
133 constexpr Tensor(X &&other)
134 {
135 *this = forward<X>(other);
136 }
137
145 template<class X,
147 constexpr auto &operator=(X &&rhs) &
148 {
149 view(*this) = forward<X>(rhs);
150 return *this;
151 }
152
162 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
163 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
164 constexpr decltype(auto) operator()(Is const... indices) &&
165 {
166 return move(mData)(indices...);
167 }
168
178 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
179 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
180 constexpr decltype(auto) operator()(Is const... indices) const &&
181 {
182 return move(mData)(indices...);
183 }
184
194 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
195 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
196 constexpr decltype(auto) operator()(Is const... indices) &
197 {
198 return mData(indices...);
199 }
200
209 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
210 If<IsSatisfied<(sizeof...(Is) == Dimension())>> = 0>
211 constexpr decltype(auto) operator()(Is const... indices) const &
212 {
213 return mData(indices...);
214 }
215
225 constexpr decltype(auto) operator()(Subscripts const &subscripts) &&
226 {
227 return move(mData)(subscripts);
228 }
229
239 constexpr decltype(auto) operator()(
240 Subscripts const &subscripts) const &&
241 {
242 return move(mData)(subscripts);
243 }
244
254 constexpr decltype(auto) operator()(Subscripts const &subscripts) &
255 {
256 return mData(subscripts);
257 }
258
268 constexpr decltype(auto) operator()(
269 Subscripts const &subscripts) const &
270 {
271 return mData(subscripts);
272 }
273
279 constexpr decltype(auto) operator[](Index const index) &&
280 {
281 return move(mData)[index];
282 }
283
289 constexpr decltype(auto) operator[](Index const index) const &&
290 {
291 return move(mData)[index];
292 }
293
299 constexpr decltype(auto) operator[](Index const index) &
300 {
301 return mData[index];
302 }
303
309 constexpr decltype(auto) operator[](Index const index) const &
310 {
311 return mData[index];
312 }
313
321 explicit constexpr operator Bool() const
322 {
323 return reduce<LogicalAnd>(*this)();
324 }
325
326 private:
327 BEGIN_IGNORE_DIAGNOSTIC_GCC("-Wpedantic")
328 Array<Bool, Ns...> mData;
330 };
331}
332#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)
Returns the mode size along a particular axis of the Tensor class.
Definition bool.hpp:65
constexpr Tensor(Tensor &&)=default
static constexpr auto Single(X &&value, Subscripts const &subscripts)
Returns a Tensor of the Tensor class with a single non-zero entry.
Definition bool.hpp:110
constexpr Tensor & operator=(Tensor const &) &=default
typename Sizes::Dimension Dimension
Definition bool.hpp:48
constexpr Tensor()=default
constexpr Tensor(X &&other)
Tensor initializer from compatible tensorish object.
Definition bool.hpp:133
static constexpr auto Single(X &&value, Is const ... indices)
Returns a Tensor of the Tensor class with a single non-zero entry.
Definition bool.hpp:90
static constexpr auto size()
Returns the number of entries of the Tensor class.
Definition bool.hpp:54
constexpr auto & operator=(X &&rhs) &
Tensor assignment from compatible tensorish objects.
Definition bool.hpp:147
constexpr decltype(auto) operator()(Is const ... indices) const &
Getter for const lvalue Tensor entries from indices.
Definition bool.hpp:211
Bool Type
Definition bool.hpp:38
constexpr decltype(auto) operator()(Is const ... indices) &
Getter/setter for lvalue Tensor entries from indices.
Definition bool.hpp:196
constexpr decltype(auto) operator()(Is const ... indices) &&
Getter/setter for rvalue Tensor entries from indices.
Definition bool.hpp:164
constexpr decltype(auto) operator()(Is const ... indices) const &&
Getter for const rvalue Tensor entries from indices.
Definition bool.hpp:180
constexpr Tensor(Tensor const &)=default
Class storing tensors.
Definition tensor.hpp:44
static constexpr auto Single(X &&value, Is const ... indices)
Returns a Tensor of the Tensor class with a single non-zero entry.
Definition tensor.hpp:120
pRC::Subscripts< Ns... > Subscripts
Definition tensor.hpp:55
typename Sizes::Dimension Dimension
Definition tensor.hpp:61
Definition cholesky.hpp:18
bool Bool
Definition type_traits.hpp:18
static constexpr X view(X &&a)
Returns a TensorView obtained from a TensorView.
Definition view.hpp:22
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
std::size_t Size
Definition type_traits.hpp:20
Conditional< IsSatisfied<((Ns *... *1) *sizeof(T) > cHugepageSizeByte)>, HeapArray< T, Ns... >, StackArray< T, Ns... > > Array
Definition type_traits.hpp:60
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
Size Index
Definition type_traits.hpp:21
#define BEGIN_IGNORE_DIAGNOSTIC_GCC(warning)
Definition pragma.hpp:42
#define END_IGNORE_DIAGNOSTIC_GCC
Definition pragma.hpp:43
Definition limits.hpp:13