pRC
multi-purpose Tensor Train library for C++
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 class Reverse<T, Sizes<Ns...>, Sequence<Bool, Rs...>, V>
16 : public Conditional<IsAssignable<V>,
17 Assignable<T, Sizes<Ns...>,
18 Reverse<T, Sizes<Ns...>, Sequence<Bool, Rs...>, V>>,
19 View<T, Sizes<Ns...>,
20 Reverse<T, Sizes<Ns...>, Sequence<Bool, Rs...>, V>>>
21 {
22 static_assert(IsTensorView<V>());
23
24 private:
25 using Base =
27 View<T, Sizes<Ns...>, Reverse>>;
28
29 public:
30 template<class X, If<IsSame<V, RemoveReference<X>>> = 0>
32 : mA(forward<X>(a))
33 {
34 }
35
36 using Base::operator=;
37
38 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
39 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
40 constexpr decltype(auto) operator()(Is const... indices)
41 {
42 return mA((Rs ? Ns - indices - 1 : indices)...);
43 }
44
45 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
46 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
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 template<class E = IsSubscriptable<V>,
65 class L = IsSame<Constant<Bool, Rs>...>, If<All<E, L>> = 0>
66 constexpr decltype(auto) operator[](Index const index)
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 template<class E = IsSubscriptable<V>,
79 class L = IsSame<Constant<Bool, Rs>...>, If<All<E, L>> = 0>
80 constexpr decltype(auto) operator[](Index const index) const
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 sequence.hpp:56
Definition sequence.hpp:34
Definition assignable.hpp:22
constexpr decltype(auto) operator()(Is const ... indices) const
Definition reverse.hpp:47
constexpr decltype(auto) operator()(Is const ... indices)
Definition reverse.hpp:40
Definition reverse.hpp:12
Definition type_traits.hpp:32
Definition diagonal.hpp:11
bool Bool
Definition type_traits.hpp:18
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
std::size_t Size
Definition type_traits.hpp:20
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
std::conditional_t< B{}, T, F > Conditional
Definition type_traits.hpp:131
Size Index
Definition type_traits.hpp:21