pRC
multi-purpose Tensor Train library for C++
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
26 template<Index K, class X, class R = RemoveReference<X>,
27 If<IsTensorish<R>> = 0, If<IsInvocable<View, X>> = 0,
28 If<IsSatisfied<(typename R::Dimension{} > 1)>> = 0,
29 If<IsSatisfied<(K < typename R::Dimension{})>> = 0>
30 static inline constexpr auto flatten(X &&a)
31 {
32 return expand(chip<K>(makeSeries<Index, typename R::Dimension{}>()),
33 [&a](auto const... seq)
34 {
35 return reshape<R::size(K),
36 decltype(chip<K>(typename R::Sizes()))::size()>(
37 permute<K, seq...>(forward<X>(a)));
38 });
39 }
40
57 template<Index K, class X, class R = RemoveReference<X>,
58 If<IsTensorish<R>> = 0, If<Not<IsInvocable<View, X>>> = 0,
59 If<IsSatisfied<(typename R::Dimension{} > 1)>> = 0,
60 If<IsSatisfied<(K < typename R::Dimension{})>> = 0>
61 static inline constexpr auto flatten(X &&a)
62 {
63 return eval(flatten<K>(a));
64 }
65}
66#endif // pRC_CORE_TENSOR_FUNCTIONS_FLATTEN_H
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
static constexpr auto flatten(X &&a)
Flatten every dimension of a Tensor except for one.
Definition flatten.hpp:30
static constexpr auto makeSeries()
Definition sequence.hpp:361
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto permute(Sequence< T, Is... > const)
Definition sequence.hpp:450
static constexpr auto reshape(X &&a)
Reshapes a Tensor.
Definition reshape.hpp:29
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
forwards the values in a pRC::Sequence to a function as parameters
Definition sequence.hpp:354
Size Index
Definition type_traits.hpp:21