cMHN 1.2
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<IsConvertible<Index>... Is>
32 requires(sizeof...(Is) == Base::Dimension)
33 constexpr decltype(auto) operator()(Is const... indices)
34 {
35 return mA(indices...);
36 }
37
38 template<IsConvertible<Index>... Is>
39 requires(sizeof...(Is) == Base::Dimension)
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 value.hpp:12
Definition sequence.hpp:29
Definition assignable.hpp:21
Reference(Tensor< T, Ns... > &a)
Definition reference.hpp:24
Definition reference.hpp:11
Definition tensor.hpp:25
pRC::Float<> T
Definition externs_nonTT.hpp:1
Definition declarations.hpp:18
Reference(Tensor< T, Ns... > &) -> Reference< T, Sizes< Ns... > >
Size Index
Definition basics.hpp:32
std::size_t Size
Definition basics.hpp:31
static constexpr AddConst< X > & asConst(X &a)
Definition basics.hpp:71