cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
contract.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_CONTRACT_H
4#define pRC_CORE_TENSOR_VIEWS_CONTRACT_H
5
9
10namespace pRC::TensorViews
11{
12 template<class T, class N, class S1, class S2, class V>
13 class Contract;
14
15 template<class T, class N, Index... ILs, Index... IRs, class V>
16 requires IsTensorView<V> && ((V::size(ILs) == V::size(IRs)) && ...)
17 class Contract<T, N, Sequence<Index, ILs...>, Sequence<Index, IRs...>, V>
18 : public View<T, N,
19 Contract<T, N, Sequence<Index, ILs...>, Sequence<Index, IRs...>,
20 V>>
21 {
22 private:
24
25 public:
26 template<class X>
28 Contract(X &&a)
29 : mA(forward<X>(a))
30 {
31 }
32
33 template<IsConvertible<Index>... Is>
34 requires(sizeof...(Is) == Base::Dimension)
35 constexpr decltype(auto) operator()(Is const... indices)
36 {
37 auto c = Add::template Identity<T>();
38
39 range<Sizes<V::size(ILs)...>>(
40 [this, &c, indices...](auto const... loop)
41 {
42 c += chip<ILs..., IRs...>(mA, loop..., loop...)(indices...);
43 });
44
45 return c;
46 }
47
48 template<IsConvertible<Index>... Is>
49 requires(sizeof...(Is) == Base::Dimension)
50 constexpr decltype(auto) operator()(Is const... indices) const
51 {
52 auto c = Add::template Identity<T>();
53
54 range<Sizes<V::size(ILs)...>>(
55 [this, &c, indices...](auto const... loop)
56 {
57 c += chip<ILs..., IRs...>(mA, loop..., loop...)(indices...);
58 });
59
60 return c;
61 }
62
63 constexpr decltype(auto) operator()(
64 typename Base::Subscripts const &subscripts)
65 {
66 return this->call(subscripts);
67 }
68
69 constexpr decltype(auto) operator()(
70 typename Base::Subscripts const &subscripts) const
71 {
72 return this->call(subscripts);
73 }
74
75 constexpr decltype(auto) operator[](Index const index) = delete;
76 constexpr decltype(auto) operator[](Index const index) const = delete;
77
78 private:
79 V mA;
80 };
81}
82#endif // pRC_CORE_TENSOR_VIEWS_CONTRACT_H
Definition value.hpp:12
Definition sequence.hpp:29
Definition contract.hpp:13
Definition declarations.hpp:20
Definition concepts.hpp:28
Definition declarations.hpp:36
pRC::Float<> T
Definition externs_nonTT.hpp:1
Definition declarations.hpp:18
Size Index
Definition basics.hpp:32
static constexpr auto loop(F &&f, Xs &&...args)
Definition loop.hpp:20
static constexpr auto chip(Sequence< T, Is... > const)
Definition sequence.hpp:584
static constexpr auto range(F &&f, Xs &&...args)
Definition range.hpp:18
Definition identity.hpp:11