pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
permute.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_PERMUTE_H
4#define pRC_CORE_TENSOR_VIEWS_PERMUTE_H
5
9
10namespace pRC::TensorViews
11{
12 template<class T, class N, class P, class V>
13 class Permute;
14
15 template<class T, class N, Index... Ps, class V>
16 class Permute<T, N, Sequence<Index, Ps...>, V>
17 : public Conditional<IsAssignable<V>,
18 Assignable<T, N, Permute<T, N, Sequence<Index, Ps...>, V>>,
19 View<T, N, Permute<T, N, Sequence<Index, Ps...>, V>>>
20 {
21 static_assert(IsTensorView<V>());
22
23 private:
26
27 public:
28 template<class X, If<IsSame<V, RemoveReference<X>>> = 0>
30 : mA(forward<X>(a))
31 {
32 }
33
34 using Base::operator=;
35
36 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
37 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
38 constexpr decltype(auto) operator()(Is const... indices)
39 {
40 return expand(
42 [this](auto const &indices, auto const... seq) -> decltype(auto)
43 {
44 return mA(indices[seq]...);
45 },
46 Indices<sizeof...(Is)>(indices...));
47 }
48
49 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
50 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
51 constexpr decltype(auto) operator()(Is const... indices) const
52 {
53 return expand(
55 [this](auto const &indices, auto const... seq) -> decltype(auto)
56 {
57 return mA(indices[seq]...);
58 },
59 Indices<sizeof...(Is)>(indices...));
60 }
61
62 constexpr decltype(auto) operator()(
63 typename Base::Subscripts const &subscripts)
64 {
65 return this->call(subscripts);
66 }
67
68 constexpr decltype(auto) operator()(
69 typename Base::Subscripts const &subscripts) const
70 {
71 return this->call(subscripts);
72 }
73
74 template<class E = IsSubscriptable<V>,
75 class L = IsSatisfied<(
76 Sequence<Index, Ps...>() == makeSeriesFor<Index, Ps...>())>,
77 If<All<E, L>> = 0>
78 constexpr decltype(auto) operator[](Index const index)
79 {
80 return mA[index];
81 }
82
83 template<class E = IsSubscriptable<V>,
84 class L = IsSatisfied<(
85 Sequence<Index, Ps...>() == makeSeriesFor<Index, Ps...>())>,
86 If<All<E, L>> = 0>
87 constexpr decltype(auto) operator[](Index const index) const
88 {
89 return mA[index];
90 }
91
92 private:
93 V mA;
94 };
95}
96#endif // pRC_CORE_TENSOR_VIEWS_PERMUTE_H
Definition indices.hpp:15
Definition sequence.hpp:34
Definition assignable.hpp:22
constexpr decltype(auto) operator()(Is const ... indices) const
Definition permute.hpp:51
constexpr decltype(auto) operator()(Is const ... indices)
Definition permute.hpp:38
Definition permute.hpp:13
Definition type_traits.hpp:32
Definition diagonal.hpp:11
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
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
static constexpr auto getPermutation(Sequence< T, From, Froms... > const, Sequence< T, To, Tos... > const, Sequence< T, P, Ps... > const)
Definition sequence.hpp:653
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
forwards the values in a pRC::Sequence to a function as parameters
Definition sequence.hpp:354
Size Index
Definition type_traits.hpp:21