cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
single.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_SINGLE_H
4#define pRC_CORE_TENSOR_VIEWS_SINGLE_H
5
8
9namespace pRC::TensorViews
10{
11 template<class T, class N>
12 class Single : public View<T, N, Single<T, N>>
13 {
14 private:
16
17 public:
18 template<class X, If<IsConstructible<T, X>> = 0>
19 Single(X &&value, typename Base::Subscripts const &subscripts)
20 : mValue(forward<X>(value))
21 , mSubscripts(subscripts)
22 {
23 }
24
25 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
26 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
27 constexpr decltype(auto) operator()(Is const... indices) const
28 {
29 return (*this)(typename Base::Subscripts(indices...));
30 }
31
32 constexpr T operator()(
33 typename Base::Subscripts const &subscripts) const
34 {
35 if(subscripts == mSubscripts)
36 {
37 return mValue;
38 }
39 else
40 {
41 return zero();
42 }
43 }
44
45 private:
46 T const mValue;
47 typename Base::Subscripts const mSubscripts;
48 };
49}
50#endif // pRC_CORE_TENSOR_VIEWS_SINGLE_H
Definition single.hpp:13
constexpr T operator()(typename Base::Subscripts const &subscripts) const
Definition single.hpp:32
Single(X &&value, typename Base::Subscripts const &subscripts)
Definition single.hpp:19
constexpr decltype(auto) operator()(Is const ... indices) const
Definition single.hpp:27
Definition type_traits.hpp:32
Definition diagonal.hpp:11
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
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