cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
reverse.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_REVERSE_H
4#define pRC_CORE_TENSOR_VIEWS_REVERSE_H
5
8
9namespace pRC::TensorViews
10{
11 template<class T, class N, class R, class V>
12 class Reverse;
13
14 template<class T, Size... Ns, Bool... Rs, class V>
15 requires IsTensorView<V>
16 class Reverse<T, Sizes<Ns...>, Sequence<Bool, Rs...>, V>
17 : public Conditional<IsAssignable<V>,
18 Assignable<T, Sizes<Ns...>,
19 Reverse<T, Sizes<Ns...>, Sequence<Bool, Rs...>, V>>,
20 View<T, Sizes<Ns...>,
21 Reverse<T, Sizes<Ns...>, Sequence<Bool, Rs...>, V>>>
22 {
23 private:
24 using Base =
26 View<T, Sizes<Ns...>, Reverse>>;
27
28 public:
29 template<class X>
31 Reverse(X &&a)
32 : mA(forward<X>(a))
33 {
34 }
35
36 using Base::operator=;
37
38 template<IsConvertible<Index>... Is>
39 requires(sizeof...(Is) == Base::Dimension)
40 constexpr decltype(auto) operator()(Is const... indices)
41 {
42 return mA((Rs ? Ns - indices - 1 : indices)...);
43 }
44
45 template<IsConvertible<Index>... Is>
46 requires(sizeof...(Is) == Base::Dimension)
47 constexpr decltype(auto) operator()(Is const... indices) const
48 {
49 return mA((Rs ? Ns - indices - 1 : indices)...);
50 }
51
52 constexpr decltype(auto) operator()(
53 typename Base::Subscripts const &subscripts)
54 {
55 return this->call(subscripts);
56 }
57
58 constexpr decltype(auto) operator()(
59 typename Base::Subscripts const &subscripts) const
60 {
61 return this->call(subscripts);
62 }
63
64 constexpr decltype(auto) operator[](Index const index)
65 requires IsSubscriptable<V> &&
66 (((Rs == false) && ...) || (Rs && ...))
67 {
68 if constexpr((Rs && ...))
69 {
70 return mA[Base::size() - 1 - index];
71 }
72 else
73 {
74 return mA[index];
75 }
76 }
77
78 constexpr decltype(auto) operator[](Index const index) const
79 requires IsSubscriptable<V> &&
80 (((Rs == false) && ...) || (Rs && ...))
81 {
82 if constexpr((Rs && ...))
83 {
84 return mA[Base::size() - 1 - index];
85 }
86 else
87 {
88 return mA[index];
89 }
90 }
91
92 private:
93 V mA;
94 };
95}
96#endif // pRC_CORE_TENSOR_VIEWS_REVERSE_H
Definition gtest_unittest.cc:5120
Definition value.hpp:12
Definition sequence.hpp:29
Definition assignable.hpp:21
Definition reverse.hpp:12
Definition declarations.hpp:20
Definition concepts.hpp:28
Definition subscript.hpp:21
Definition declarations.hpp:36
pRC::Float<> T
Definition externs_nonTT.hpp:1
Definition declarations.hpp:18
Size Index
Definition basics.hpp:32
std::size_t Size
Definition basics.hpp:31
std::conditional_t< B, T, F > Conditional
Definition basics.hpp:56
Definition gtest_pred_impl_unittest.cc:54