cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
reference.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_REFERENCE_H
4#define pRC_CORE_TENSOR_VIEWS_REFERENCE_H
5
7
8namespace pRC::TensorViews
9{
10 template<class T, class N>
11 class Reference;
12
13 template<class T, Size... Ns>
15
16 template<class T, Size... Ns>
17 class Reference<T, Sizes<Ns...>>
18 : public Assignable<T, Sizes<Ns...>, Reference<T, Sizes<Ns...>>>
19 {
20 private:
21 using Base = Assignable<T, Sizes<Ns...>, Reference>;
22
23 public:
25 : mA(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 mA(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 asConst(mA)(indices...);
43 }
44
45 constexpr decltype(auto) operator()(
46 typename Base::Subscripts const &subscripts)
47 {
48 return mA(subscripts);
49 }
50
51 constexpr decltype(auto) operator()(
52 typename Base::Subscripts const &subscripts) const
53 {
54 return asConst(mA)(subscripts);
55 }
56
57 constexpr decltype(auto) operator[](Index const index)
58 {
59 return mA[index];
60 }
61
62 constexpr decltype(auto) operator[](Index const index) const
63 {
64 return asConst(mA)[index];
65 }
66
67 private:
68 Tensor<T, Ns...> &mA;
69 };
70}
71#endif // pRC_CORE_TENSOR_VIEWS_REFERENCE_H
Definition sequence.hpp:56
Definition assignable.hpp:22
constexpr decltype(auto) operator()(Is const ... indices) const
Definition reference.hpp:40
constexpr decltype(auto) operator()(Is const ... indices)
Definition reference.hpp:33
Reference(Tensor< T, Ns... > &a)
Definition reference.hpp:24
Definition reference.hpp:11
Definition tensor.hpp:28
pRC::Float<> T
Definition externs_nonTT.hpp:1
Definition diagonal.hpp:11
Reference(Tensor< T, Ns... > &) -> Reference< T, Sizes< Ns... > >
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
std::size_t Size
Definition type_traits.hpp:20
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
AddConst< T > & asConst(T &a)
Definition type_traits.hpp:208