cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
loop.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_TENSOR_TRAIN_TENSOR_VIEWS_LOOP_H
4#define pRC_TENSOR_TRAIN_TENSOR_VIEWS_LOOP_H
5
9
11{
12 template<class T, class N, class Ranks, class F, class... Vs>
13 class Loop
14 : public Conditional<
15 IsAssignable<
16 ResultOf<F, decltype(declval<Vs>().template core<0>())...>>,
17 Assignable<T, N, Ranks, Loop<T, N, Ranks, F, Vs...>>,
18 View<T, N, Ranks, Loop<T, N, Ranks, F, Vs...>>>
19 {
20 static_assert(All<Any<IsTensorView<Vs>, IsOperatorView<Vs>>...>());
21
22 private:
23 using Base =
25 decltype(declval<Vs>().template core<0>())...>>,
27
28 public:
29 template<class... Xs, If<All<IsSame<Vs, RemoveReference<Xs>>...>> = 0>
30 Loop(F f, Xs &&...args)
31 : mF(forward<F>(f))
32 , mArgs(forward<Xs>(args)...)
33 {
34 }
35
36 using Base::operator=;
37
38 template<Index C>
39 constexpr decltype(auto) core()
40 {
42 [this](auto const... ops) -> decltype(auto)
43 {
44 return mF(get<ops>(mArgs).template core<C>()...);
45 });
46 }
47
48 template<Index C>
49 constexpr decltype(auto) core() const
50 {
52 [this](auto const... ops) -> decltype(auto)
53 {
54 return mF(get<ops>(mArgs).template core<C>()...);
55 });
56 }
57
58 private:
59 F mF;
60 tuple<Vs...> mArgs;
61 };
62}
63#endif // pRC_TENSOR_TRAIN_TENSOR_VIEWS_LOOP_H
Definition type_traits.hpp:40
Loop(F f, Xs &&...args)
Definition loop.hpp:30
constexpr decltype(auto) core()
Definition loop.hpp:39
constexpr decltype(auto) core() const
Definition loop.hpp:49
Definition type_traits.hpp:37
pRC::Float<> T
Definition externs_nonTT.hpp:1
Definition type_traits.hpp:35
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
std::invoke_result_t< F, Args... > ResultOf
Definition type_traits.hpp:140
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
std::is_assignable< T, U > IsAssignable
Definition type_traits.hpp:146
std::conditional_t< B{}, T, F > Conditional
Definition type_traits.hpp:131
std::conjunction< Bs... > All
Definition type_traits.hpp:77
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
Definition sequence.hpp:344
Definition type_traits.hpp:66