TensorSyclTuple.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Mehdi Goli Codeplay Software Ltd.
5 // Ralph Potter Codeplay Software Ltd.
6 // Luke Iwanski Codeplay Software Ltd.
7 // Contact: <eigen@codeplay.com>
8 //
9 // This Source Code Form is subject to the terms of the Mozilla
10 // Public License v. 2.0. If a copy of the MPL was not distributed
11 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 
13 /*****************************************************************
14  * TensroSyclTuple.h
15  *
16  * \brief:
17  * Minimal implementation of std::tuple that can be used inside a SYCL kernel.
18  *
19 *****************************************************************/
20 
21 #ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_TUPLE_HPP
22 #define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_TUPLE_HPP
23 namespace utility {
24 namespace tuple {
28 template <bool, typename T = void> struct StaticIf;
30 template <typename T>
31 struct StaticIf<true, T> {
32  typedef T type;
33 };
34 
39 template <class... Ts>
40 struct Tuple {};
41 
46 template <class T, class... Ts>
47 struct Tuple<T, Ts...> {
48  Tuple(T t, Ts... ts) : head(t), tail(ts...) {}
50  Tuple<Ts...> tail;
51 };
52 
58 template <size_t, class>
60 
63 template <class T, class... Ts>
64 struct ElemTypeHolder<0, Tuple<T, Ts...> > {
65  typedef T type;
66 };
67 
74 template <size_t k, class T, class... Ts>
75 struct ElemTypeHolder<k, Tuple<T, Ts...> > {
76  typedef typename ElemTypeHolder<k - 1, Tuple<Ts...> >::type type;
77 };
78 
85 
86 #define TERMINATE_CONDS_TUPLE_GET(CVQual) \
87 template <size_t k, class... Ts> \
88 typename StaticIf<k == 0, CVQual typename ElemTypeHolder<0, Tuple<Ts...> >::type &>::type \
89 get(CVQual Tuple<Ts...> &t) { \
90  static_assert(sizeof...(Ts)!=0, "The requseted value is bigger than the size of the tuple"); \
91  return t.head; \
92 }
93 
96 #undef TERMINATE_CONDS_TUPLE_GET
97 #define RECURSIVE_TUPLE_GET(CVQual) \
105 template <size_t k, class T, class... Ts> \
106 typename StaticIf<k != 0, CVQual typename ElemTypeHolder<k, Tuple<T, Ts...> >::type &>::type \
107 get(CVQual Tuple<T, Ts...> &t) { \
108  return utility::tuple::get<k - 1>(t.tail); \
109 }
110 RECURSIVE_TUPLE_GET(const)
112 #undef RECURSIVE_TUPLE_GET
113 
120 template <typename... Args>
121 Tuple<Args...> make_tuple(Args... args) {
122  return Tuple<Args...>(args...);
123 }
124 
130 template <typename... Args>
131 static constexpr size_t size(Tuple<Args...> &) {
132  return sizeof...(Args);
133 }
134 
138 template <size_t... Is>
139 struct IndexList {};
140 
147 template <size_t MIN, size_t N, size_t... Is>
149 
150 // FIXME Doxygen has problems with recursive inheritance
151 #ifndef EIGEN_PARSED_BY_DOXYGEN
152 template <size_t MIN, size_t... Is>
157 struct RangeBuilder<MIN, MIN, Is...> {
158  typedef IndexList<Is...> type;
159 };
160 
167 template <size_t MIN, size_t N, size_t... Is>
168 struct RangeBuilder : public RangeBuilder<MIN, N - 1, N - 1, Is...> {};
169 #endif // EIGEN_PARSED_BY_DOXYGEN
170 
174 template <size_t MIN, size_t MAX>
175 struct IndexRange: RangeBuilder<MIN, MAX>::type {};
176 
186 template <typename... Args, typename T, size_t... I>
188  return utility::tuple::make_tuple(get<I>(t)..., a);
189 }
190 
199 template <typename... Args, typename T>
200 Tuple<Args..., T> append(Tuple<Args...> t, T a) {
201  return utility::tuple::append_base(t, a, IndexRange<0, sizeof...(Args)>());
202 }
203 
217 template <typename... Args1, typename... Args2, size_t... I1, size_t... I2>
219  return utility::tuple::make_tuple(get<I1>(t1)...,get<I2>(t2)...);
220 }
221 
231 template <typename... Args1, typename... Args2>
232 Tuple<Args1..., Args2...> append(Tuple<Args1...> t1,Tuple<Args2...> t2) {
233  return utility::tuple::append_base(t1, t2, IndexRange<0, sizeof...(Args1)>(), IndexRange<0, sizeof...(Args2)>());
234 }
235 } // tuple
236 } // utility
237 #endif // UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_TUPLE_HPP
The StaticIf struct is used to statically choose the type based on the condition. ...
ElemTypeHolder class is used to specify the types of the elements inside the tuple.
EIGEN_DEVICE_FUNC SegmentReturnType tail(Index n)
This is the const version of tail(Index).
Definition: BlockMethods.h:949
Collects internal details for generating index ranges [MIN, MAX) Declare primary template for index r...
Definition: pytypes.h:1322
Tuple< Args..., T > append_base(Tuple< Args... > t, T a, IndexList< I... >)
unpacking the elements of the input tuple t and creating a new tuple by adding element a at the end o...
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
Tuple< Args..., T > append(Tuple< Args... > t, T a)
the deduction function for append_base that automatically generate the IndexRange ...
ElemTypeHolder< k-1, Tuple< Ts... > >::type type
#define N
Definition: gksort.c:12
#define MIN(a, b)
IndexRange that returns a [MIN, MAX) index range.
Array33i a
Tuple< Args... > make_tuple(Args...args)
Creates a tuple object, deducing the target type from the types of arguments.
is a fixed-size collection of heterogeneous values
#define TERMINATE_CONDS_TUPLE_GET(CVQual)
Extracts the first element from the tuple. K=0 represents the first element of the tuple...
Eigen::Triplet< double > T
static const Matrix I
Definition: lago.cpp:35
#define RECURSIVE_TUPLE_GET(CVQual)
Extracts the Kth element from the tuple.
EIGEN_DEVICE_FUNC SegmentReturnType head(Index n)
This is the const version of head(Index).
Definition: BlockMethods.h:919
Creates a list of index from the elements in the tuple.
Point2 t(10, 10)
Definition: pytypes.h:897


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:01