cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
from_diagonal.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_OPERATOR_VIEWS_FROM_DIAGONAL_H
4#define pRC_CORE_TENSOR_OPERATOR_VIEWS_FROM_DIAGONAL_H
5
8
9namespace pRC::TensorViews
10{
11 template<class T, class N, class V>
12 class FromDiagonal : public View<T, N, FromDiagonal<T, N, V>>
13 {
14 static_assert(IsTensorView<V>());
15
16 private:
18
19 public:
20 template<class X, If<IsConstructible<V, X>> = 0>
22 : mA(forward<X>(a))
23 {
24 }
25
26 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
27 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
28 constexpr decltype(auto) operator()(Is const... indices)
29 {
30 return expand(
31 makeSeries<Index, typename Base::Dimension() / 2>(),
32 [this](auto const &indices, auto const... seq) -> T
33 {
34 if(((indices[seq] ==
35 indices[typename Base::Dimension() / 2 + seq]) &&
36 ...))
37 {
38 return mA(indices[seq]...);
39 }
40
41 return zero();
42 },
43 Indices<typename Base::Dimension{}>(indices...));
44 }
45
46 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
47 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
48 constexpr decltype(auto) operator()(Is const... indices) const
49 {
50 return expand(
51 makeSeries<Index, typename Base::Dimension() / 2>(),
52 [this](auto const &indices, auto const... seq) -> T
53 {
54 if(((indices[seq] ==
55 indices[typename Base::Dimension() / 2 + seq]) &&
56 ...))
57 {
58 return mA(indices[seq]...);
59 }
60
61 return zero();
62 },
63 Indices<typename Base::Dimension{}>(indices...));
64 }
65
66 constexpr decltype(auto) operator()(
67 typename Base::Subscripts const &subscripts)
68 {
69 return this->call(subscripts);
70 }
71
72 constexpr decltype(auto) operator()(
73 typename Base::Subscripts const &subscripts) const
74 {
75 return this->call(subscripts);
76 }
77
78 private:
79 V mA;
80 };
81}
82#endif // pRC_CORE_TENSOR_OPERATOR_VIEWS_FROM_DIAGONAL_H
Definition indices.hpp:15
Definition from_diagonal.hpp:13
FromDiagonal(X &&a)
Definition from_diagonal.hpp:21
constexpr decltype(auto) operator()(Is const ... indices)
Definition from_diagonal.hpp:28
constexpr decltype(auto) operator()(Is const ... indices) const
Definition from_diagonal.hpp:48
Definition type_traits.hpp:32
Definition diagonal.hpp:11
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
static constexpr auto zero()
Definition zero.hpp:12
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr auto makeSeries()
Definition sequence.hpp:351
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
Definition sequence.hpp:344