cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
unit.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_TENSOR_TRAIN_OPERATOR_UNIT_H
4#define pRC_TENSOR_TRAIN_OPERATOR_UNIT_H
5
10
11namespace pRC
12{
13 template<TensorTrain::IsOperator T>
14 struct Unit<T>
15 {
16 constexpr auto operator()() const
17 {
18 auto const f = []<Index C>()
19 {
20 using Core = typename T::template Cores<C>;
21 constexpr auto CRL = Core::size(0);
22 constexpr auto CM = Core::size(1);
23 constexpr auto CN = Core::size(2);
24 constexpr auto CRR = Core::size(3);
25
27 unit<typename Core::template ChangeSizes<1, CM, CN, 1>>(),
28 zero<typename Core::template ChangeSizes<CRL - 1, CM, CN,
29 CRR - 1>>()));
30 };
31
32 using F = RemoveConstReference<decltype(f)>;
33 using M = typename T::M;
34 using N = typename T::N;
35 using Ranks = typename T::Ranks;
36
37 return TensorTrain::OperatorViews::Enumerate<typename T::Type, M, N,
38 Ranks, F>(f);
39 }
40
41 template<class X>
43 constexpr auto operator()(X &&value) const
44 {
45 auto const f =
46 [value = typename T::Type(forward<X>(value))]<Index C>()
47 {
48 using Core = typename T::template Cores<C>;
49 constexpr auto CRL = Core::size(0);
50 constexpr auto CM = Core::size(1);
51 constexpr auto CN = Core::size(2);
52 constexpr auto CRR = Core::size(3);
53
54 if constexpr(C == 0)
55 {
57 unit<typename Core::template ChangeSizes<1, CM, CN, 1>>(
58 value),
59 zero<typename Core::template ChangeSizes<CRL - 1, CM,
60 CN, CRR - 1>>()));
61 }
62 else
63 {
65 unit<typename Core::template ChangeSizes<1, CM, CN,
66 1>>(),
67 zero<typename Core::template ChangeSizes<CRL - 1, CM,
68 CN, CRR - 1>>()));
69 }
70 };
71
72 using F = RemoveConstReference<decltype(f)>;
73 using M = typename T::M;
74 using N = typename T::N;
75 using Ranks = typename T::Ranks;
76
77 return TensorTrain::OperatorViews::Enumerate<typename T::Type, M, N,
78 Ranks, F>(f);
79 }
80 };
81
82 template<TensorTrain::IsOperatorView T>
83 struct Unit<T> : Unit<ResultOf<Eval, T>>
84 {
85 };
86}
87#endif // pRC_TENSOR_TRAIN_OPERATOR_UNIT_H
Definition value.hpp:12
Definition concepts.hpp:37
int value
Definition gmock-actions_test.cc:1714
Definition cholesky.hpp:10
static constexpr auto unit()
Definition unit.hpp:13
Size Index
Definition basics.hpp:32
RemoveConst< RemoveReference< T > > RemoveConstReference
Definition basics.hpp:47
static constexpr auto permute(Sequence< T, Is... > const)
Definition sequence.hpp:487
static constexpr auto exclude(F &&f, Xs &&...args)
Definition exclude.hpp:20
static constexpr auto zero()
Definition zero.hpp:12
constexpr auto operator()() const
Definition unit.hpp:16
constexpr auto operator()(X &&value) const
Definition unit.hpp:43