cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
flatten.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_FUNCTIONS_FLATTEN_H
4#define pRC_CORE_TENSOR_FUNCTIONS_FLATTEN_H
5
9
10namespace pRC
11{
12 template<Index K, class X, class R = RemoveReference<X>,
13 If<IsTensorish<R>> = 0, If<IsInvocable<View, X>> = 0,
14 If<IsSatisfied<(typename R::Dimension{} > 1)>> = 0,
15 If<IsSatisfied<(K < typename R::Dimension{})>> = 0>
16 static inline constexpr auto flatten(X &&a)
17 {
18 return expand(chip<K>(makeSeries<Index, typename R::Dimension{}>()),
19 [&a](auto const... seq)
20 {
21 return reshape<R::size(K),
22 decltype(chip<K>(typename R::Sizes()))::size()>(
23 permute<K, seq...>(forward<X>(a)));
24 });
25 }
26
27 template<Index K, class X, class R = RemoveReference<X>,
28 If<IsTensorish<R>> = 0, If<Not<IsInvocable<View, X>>> = 0,
29 If<IsSatisfied<(typename R::Dimension{} > 1)>> = 0,
30 If<IsSatisfied<(K < typename R::Dimension{})>> = 0>
31 static inline constexpr auto flatten(X &&a)
32 {
33 return eval(flatten<K>(a));
34 }
35}
36#endif // pRC_CORE_TENSOR_FUNCTIONS_FLATTEN_H
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr auto flatten(X &&a)
Definition flatten.hpp:16
static constexpr auto makeSeries()
Definition sequence.hpp:351
static constexpr auto permute(Sequence< T, Is... > const)
Definition sequence.hpp:440
static constexpr auto reshape(X &&a)
Definition reshape.hpp:17
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
Definition sequence.hpp:344