pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
reshape.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_RESHAPE_H
4#define pRC_CORE_TENSOR_VIEWS_RESHAPE_H
5
8
9namespace pRC::TensorViews
10{
11 template<class T, class N, class V>
12 class Reshape
13 : public Conditional<IsAssignable<V>,
14 Assignable<T, N, Reshape<T, N, V>>, View<T, N, Reshape<T, N, V>>>
15 {
16 static_assert(IsTensorView<V>());
17
18 private:
21
22 public:
23 template<class X, If<IsSame<V, RemoveReference<X>>> = 0>
25 : mA(forward<X>(a))
26 {
27 }
28
29 using Base::operator=;
30
31 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
32 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
33 constexpr decltype(auto) operator()(Is const... indices)
34 {
35 return (*this)(typename Base::Subscripts(indices...));
36 }
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) const
41 {
42 return (*this)(typename Base::Subscripts(indices...));
43 }
44
45 constexpr decltype(auto) operator()(
46 typename Base::Subscripts const &subscripts)
47 {
48 return mA(typename V::Subscripts(Index(subscripts)));
49 }
50
51 constexpr decltype(auto) operator()(
52 typename Base::Subscripts const &subscripts) const
53 {
54 return mA(typename V::Subscripts(Index(subscripts)));
55 }
56
57 template<class E = IsSubscriptable<V>, If<E> = 0>
58 constexpr decltype(auto) operator[](Index const index)
59 {
60 return mA[index];
61 }
62
63 template<class E = IsSubscriptable<V>, If<E> = 0>
64 constexpr decltype(auto) operator[](Index const index) const
65 {
66 return mA[index];
67 }
68
69 private:
70 V mA;
71 };
72}
73#endif // pRC_CORE_TENSOR_VIEWS_RESHAPE_H
Definition assignable.hpp:22
Definition reshape.hpp:15
Reshape(X &&a)
Definition reshape.hpp:24
constexpr decltype(auto) operator()(Is const ... indices) const
Definition reshape.hpp:40
constexpr decltype(auto) operator()(Is const ... indices)
Definition reshape.hpp:33
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
Size Index
Definition type_traits.hpp:21