pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
exclude.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_FUNCTIONS_EXCLUDE_H
4#define pRC_CORE_TENSOR_FUNCTIONS_EXCLUDE_H
5
9
10namespace pRC
11{
12 template<class F, Index... Es>
13 struct Exclude;
14
15 /*
16 @brief Performs an operation on Tensors, while excluding some of the
17 Tensors' dimensions
18
19 This function first chips of the dimensions specified by `Es...` from
20 all of the Tensors, then `f` is applied to the resulting Tensors. When
21 calculating an element of the resulting Tensor, the first `sizeof...(Es)`
22 indices are used to specify which index to use when `chip` is applied.
23 The remaining indices are the indices of the Tensor resulting from
24 application of `f`.
25
26 @ŧparam Es... parameter pack of class Index..., dimensions of the
27 Tensors to exclude
28 @tparam F class of the function performed on the Tensors (inferred)
29 @tparam Xs... [pRC tensorish classes](#TensorTypes) (inferred)
30
31 @param f object of class F, function performed on the Tensors
32 @param args... parameter pack of classes Xs...
33 */
34 template<Index... Es, class F, class... Xs,
37 If<IsSame<decltype(select<Es...>(
38 typename RemoveReference<Xs>::Sizes()))...>> = 0,
39 If<IsInvocable<F, ResultOf<pRC::Chip<Es...>, Xs, decltype(Es)...>...>> =
40 0,
41 If<True<decltype(select<Es...>(makeSeries<Index,
42 typename RemoveReference<Xs>::Dimension{}>()))...>> = 0>
43 static inline constexpr auto exclude(F &&f, Xs &&...args)
44 {
45 using ESizes = Common<decltype(select<Es...>(
46 typename RemoveReference<Xs>::Sizes()))...>;
47 using R = RemoveReference<
48 ResultOf<F, ResultOf<pRC::Chip<Es...>, Xs, decltype(Es)...>...>>;
49 using FSizes = typename R::Sizes;
50 using Sizes = decltype(ESizes(), FSizes());
51 using T = typename R::Type;
52
56 }
57
58 /*
59 @brief Performs an operation on Tensors, while excluding some of the
60 Tensors' dimensions
61
62 This function first chips of the dimensions specified by `Es...` from
63 all of the Tensors, then `F()` is applied to the resulting Tensors. When
64 calculating an element of the resulting Tensor, the first `sizeof...(Es)`
65 indices are used to specify which index to use when `chip` is applied.
66 The remaining indices are the indices of the Tensor resulting from
67 application of `F()`.
68
69 @ŧparam Es... parameter pack of class Index..., dimensions of the
70 Tensors to exclude
71 @tparam F [pRC Functor class](#Functors) of the operation performed on
72 the Tensors
73 @tparam Xs... [pRC tensorish classes](#TensorTypes) (inferred)
74
75 @param args... parameter pack of classes Xs...
76 */
77 template<class F, Index... Es, class... Xs,
80 If<IsSame<decltype(select<Es...>(
81 typename RemoveReference<Xs>::Sizes()))...>> = 0,
82 If<IsInvocable<F, ResultOf<pRC::Chip<Es...>, Xs, decltype(Es)...>...>> =
83 0,
84 If<True<decltype(select<Es...>(makeSeries<Index,
85 typename RemoveReference<Xs>::Dimension{}>()))...>> = 0>
86 static inline constexpr auto exclude(Xs &&...args)
87 {
88 return exclude<Es...>(F(), forward<Xs>(args)...);
89 }
90
91 /*
92 @brief Performs an operation on Tensors, while excluding some of the
93 Tensors' dimensions
94
95 This function first chips of the dimensions specified by `Es...` from
96 all of the Tensors, then `f` is applied to the resulting Tensors. When
97 calculating an element of the resulting Tensor, the first `sizeof...(Es)`
98 indices are used to specify which index to use when `chip` is applied.
99 The remaining indices are the indices of the Tensor resulting from
100 application of `f`.
101
102 This function is used if the argument can not be represented as a
103 TensorView.
104
105 @ŧparam Es... parameter pack of class Index..., dimensions of the
106 Tensors to exclude
107 @tparam F class of the function performed on the Tensors (inferred)
108 @tparam Xs... [pRC tensorish classes](#TensorTypes) (inferred)
109
110 @param f object of class F, function performed on the Tensors
111 @param args... parameter pack of classes Xs...
112 */
113 template<Index... Es, class F, class... Xs,
116 If<IsInvocable<Exclude<F, Es...>, Xs &...>> = 0>
117 static inline constexpr auto exclude(F &&f, Xs &&...args)
118 {
119 return eval(exclude<Es...>(forward<F>(f), args...));
120 }
121
122 /*
123 @brief Performs an operation on Tensors, while excluding some of the
124 Tensors' dimensions
125
126 This function first chips of the dimensions specified by `Es...` from
127 all of the Tensors, then `F()` is applied to the resulting Tensors. When
128 calculating an element of the resulting Tensor, the first `sizeof...(Es)`
129 indices are used to specify which index to use when `chip` is applied.
130 The remaining indices are the indices of the Tensor resulting from
131 application of `F()`.
132
133 This function is used if the argument can not be represented as a
134 TensorView.
135
136 @ŧparam Es... parameter pack of class Index..., dimensions of the
137 Tensors to exclude
138 @tparam F [pRC Functor class](#Functors) of the operation performed on
139 the Tensors
140 @tparam Xs... [pRC tensorish classes](#TensorTypes) (inferred)
141
142 @param args... parameter pack of classes Xs...
143 */
144 template<class F, Index... Es, class... Xs,
147 If<IsInvocable<Exclude<F, Es...>, Xs &...>> = 0>
148 static inline constexpr auto exclude(Xs &&...args)
149 {
150 return eval(exclude<F, Es...>(args...));
151 }
152}
153#endif // pRC_CORE_TENSOR_FUNCTIONS_EXCLUDE_H
Definition sequence.hpp:56
Definition sequence.hpp:34
Definition exclude.hpp:14
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr auto select(Sequence< T, Is... > const)
Definition sequence.hpp:589
Sequence< Size, Ns... > Sizes
Definition type_traits.hpp:238
std::remove_reference_t< T > RemoveReference
Definition type_traits.hpp:56
static constexpr X view(X &&a)
Returns a TensorView obtained from a TensorView.
Definition view.hpp:22
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_invocable< F, Args... > IsInvocable
Definition type_traits.hpp:134
static constexpr auto makeSeries()
Definition sequence.hpp:361
typename CommonTypes< Ts... >::Type Common
Definition common.hpp:55
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
Size Index
Definition type_traits.hpp:21
static constexpr auto exclude(F &&f, Xs &&...args)
Definition exclude.hpp:43
Definition chip.hpp:13