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