pRC
multi-purpose Tensor Train library for C++
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_TENSOR_UNIT_H
4#define pRC_TENSOR_TRAIN_TENSOR_UNIT_H
5
10
11namespace pRC
12{
13 template<class T>
14 struct Unit<T, If<TensorTrain::IsTensorView<T>>> : Unit<ResultOf<Eval, T>>
15 {
16 };
17
18 template<class T>
19 struct Unit<T, If<TensorTrain::IsTensor<T>>>
20 {
21 constexpr auto operator()()
22 {
23 auto const f = []<Index C>()
24 {
25 using Core = typename T::template Cores<C>;
26 constexpr auto CRL = Core::size(0);
27 constexpr auto CN = Core::size(1);
28 constexpr auto CRR = Core::size(2);
29
31 unit<typename Core::template ChangeSizes<1, CN, 1>>(),
32 zero<typename Core::template ChangeSizes<CRL - 1, CN,
33 CRR - 1>>()));
34 };
35
36 using F = RemoveConstReference<decltype(f)>;
37 using N = typename T::N;
38 using Ranks = typename T::Ranks;
39
40 return TensorTrain::TensorViews::Enumerate<typename T::Type, N,
41 Ranks, F>(f);
42 }
43
44 template<class X, If<IsConstructible<typename T::Type, X>> = 0>
45 constexpr auto operator()(X &&value)
46 {
47 auto const f =
48 [value = typename T::Type(forward<X>(value))]<Index C>()
49 {
50 using Core = typename T::template Cores<C>;
51 constexpr auto CRL = Core::size(0);
52 constexpr auto CN = Core::size(1);
53 constexpr auto CRR = Core::size(2);
54
55 if constexpr(C == 0)
56 {
58 unit<typename Core::template ChangeSizes<1, CN, 1>>(
59 value),
60 zero<typename Core::template ChangeSizes<CRL - 1, CN,
61 CRR - 1>>()));
62 }
63 else
64 {
66 unit<typename Core::template ChangeSizes<1, CN, 1>>(),
67 zero<typename Core::template ChangeSizes<CRL - 1, CN,
68 CRR - 1>>()));
69 }
70 };
71
72 using F = RemoveConstReference<decltype(f)>;
73 using N = typename T::N;
74 using Ranks = typename T::Ranks;
75
76 return TensorTrain::TensorViews::Enumerate<typename T::Type, N,
77 Ranks, F>(f);
78 }
79 };
80}
81#endif // pRC_TENSOR_TRAIN_TENSOR_UNIT_H
Definition enumerate.hpp:19
Definition cholesky.hpp:18
static constexpr auto zero()
Definition zero.hpp:12
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto unit()
Definition unit.hpp:12
RemoveConst< RemoveReference< T > > RemoveConstReference
Definition type_traits.hpp:62
Size Index
Definition type_traits.hpp:21
Definition type_traits.hpp:60
Definition type_traits.hpp:16
constexpr auto operator()(X &&value)
Definition unit.hpp:45
constexpr auto operator()()
Definition unit.hpp:21
Definition type_traits.hpp:265