MoreMeta.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 // Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_MOREMETA_H
12 #define EIGEN_MOREMETA_H
13 
14 #include "../InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 template<typename... tt>
21 struct type_list { constexpr static int count = sizeof...(tt); };
22 
23 template<typename t, typename... tt>
24 struct type_list<t, tt...> { constexpr static int count = sizeof...(tt) + 1; typedef t first_type; };
25 
26 template<typename T, T... nn>
27 struct numeric_list { constexpr static std::size_t count = sizeof...(nn); };
28 
29 template<typename T, T n, T... nn>
30 struct numeric_list<T, n, nn...> { static constexpr std::size_t count = sizeof...(nn) + 1;
31  static constexpr T first_value = n; };
32 
33 #ifndef EIGEN_PARSED_BY_DOXYGEN
34 /* numeric list constructors
35  *
36  * equivalencies:
37  * constructor result
38  * typename gen_numeric_list<int, 5>::type numeric_list<int, 0,1,2,3,4>
39  * typename gen_numeric_list_reversed<int, 5>::type numeric_list<int, 4,3,2,1,0>
40  * typename gen_numeric_list_swapped_pair<int, 5,1,2>::type numeric_list<int, 0,2,1,3,4>
41  * typename gen_numeric_list_repeated<int, 0, 5>::type numeric_list<int, 0,0,0,0,0>
42  */
43 
44 template<typename T, std::size_t n, T start = 0, T... ii> struct gen_numeric_list : gen_numeric_list<T, n-1, start, start + n-1, ii...> {};
45 template<typename T, T start, T... ii> struct gen_numeric_list<T, 0, start, ii...> { typedef numeric_list<T, ii...> type; };
46 
47 template<typename T, std::size_t n, T start = 0, T... ii> struct gen_numeric_list_reversed : gen_numeric_list_reversed<T, n-1, start, ii..., start + n-1> {};
48 template<typename T, T start, T... ii> struct gen_numeric_list_reversed<T, 0, start, ii...> { typedef numeric_list<T, ii...> type; };
49 
50 template<typename T, std::size_t n, T a, T b, T start = 0, T... ii> struct gen_numeric_list_swapped_pair : gen_numeric_list_swapped_pair<T, n-1, a, b, start, (start + n-1) == a ? b : ((start + n-1) == b ? a : (start + n-1)), ii...> {};
51 template<typename T, T a, T b, T start, T... ii> struct gen_numeric_list_swapped_pair<T, 0, a, b, start, ii...> { typedef numeric_list<T, ii...> type; };
52 
53 template<typename T, std::size_t n, T V, T... nn> struct gen_numeric_list_repeated : gen_numeric_list_repeated<T, n-1, V, V, nn...> {};
54 template<typename T, T V, T... nn> struct gen_numeric_list_repeated<T, 0, V, nn...> { typedef numeric_list<T, nn...> type; };
55 
56 /* list manipulation: concatenate */
57 
58 template<class a, class b> struct concat;
59 
60 template<typename... as, typename... bs> struct concat<type_list<as...>, type_list<bs...>> { typedef type_list<as..., bs...> type; };
61 template<typename T, T... as, T... bs> struct concat<numeric_list<T, as...>, numeric_list<T, bs...> > { typedef numeric_list<T, as..., bs...> type; };
62 
63 template<typename... p> struct mconcat;
64 template<typename a> struct mconcat<a> { typedef a type; };
65 template<typename a, typename b> struct mconcat<a, b> : concat<a, b> {};
66 template<typename a, typename b, typename... cs> struct mconcat<a, b, cs...> : concat<a, typename mconcat<b, cs...>::type> {};
67 
68 /* list manipulation: extract slices */
69 
70 template<int n, typename x> struct take;
71 template<int n, typename a, typename... as> struct take<n, type_list<a, as...>> : concat<type_list<a>, typename take<n-1, type_list<as...>>::type> {};
72 template<int n> struct take<n, type_list<>> { typedef type_list<> type; };
73 template<typename a, typename... as> struct take<0, type_list<a, as...>> { typedef type_list<> type; };
74 template<> struct take<0, type_list<>> { typedef type_list<> type; };
75 
76 template<typename T, int n, T a, T... as> struct take<n, numeric_list<T, a, as...>> : concat<numeric_list<T, a>, typename take<n-1, numeric_list<T, as...>>::type> {};
77 // XXX The following breaks in gcc-11, and is invalid anyways.
78 // template<typename T, int n> struct take<n, numeric_list<T>> { typedef numeric_list<T> type; };
79 template<typename T, T a, T... as> struct take<0, numeric_list<T, a, as...>> { typedef numeric_list<T> type; };
80 template<typename T> struct take<0, numeric_list<T>> { typedef numeric_list<T> type; };
81 
82 template<typename T, int n, T... ii> struct h_skip_helper_numeric;
83 template<typename T, int n, T i, T... ii> struct h_skip_helper_numeric<T, n, i, ii...> : h_skip_helper_numeric<T, n-1, ii...> {};
84 template<typename T, T i, T... ii> struct h_skip_helper_numeric<T, 0, i, ii...> { typedef numeric_list<T, i, ii...> type; };
85 template<typename T, int n> struct h_skip_helper_numeric<T, n> { typedef numeric_list<T> type; };
86 template<typename T> struct h_skip_helper_numeric<T, 0> { typedef numeric_list<T> type; };
87 
88 template<int n, typename... tt> struct h_skip_helper_type;
89 template<int n, typename t, typename... tt> struct h_skip_helper_type<n, t, tt...> : h_skip_helper_type<n-1, tt...> {};
90 template<typename t, typename... tt> struct h_skip_helper_type<0, t, tt...> { typedef type_list<t, tt...> type; };
91 template<int n> struct h_skip_helper_type<n> { typedef type_list<> type; };
92 template<> struct h_skip_helper_type<0> { typedef type_list<> type; };
93 #endif //not EIGEN_PARSED_BY_DOXYGEN
94 
95 template<int n>
96 struct h_skip {
97  template<typename T, T... ii>
98  constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_numeric<T, n, ii...>::type helper(numeric_list<T, ii...>) { return typename h_skip_helper_numeric<T, n, ii...>::type(); }
99  template<typename... tt>
100  constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_type<n, tt...>::type helper(type_list<tt...>) { return typename h_skip_helper_type<n, tt...>::type(); }
101 };
102 
103 template<int n, typename a> struct skip { typedef decltype(h_skip<n>::helper(a())) type; };
104 
105 template<int start, int count, typename a> struct slice : take<count, typename skip<start, a>::type> {};
106 
107 /* list manipulation: retrieve single element from list */
108 
109 template<int n, typename x> struct get;
110 
111 template<int n, typename a, typename... as> struct get<n, type_list<a, as...>> : get<n-1, type_list<as...>> {};
112 template<typename a, typename... as> struct get<0, type_list<a, as...>> { typedef a type; };
113 
114 template<typename T, int n, T a, T... as> struct get<n, numeric_list<T, a, as...>> : get<n-1, numeric_list<T, as...>> {};
115 template<typename T, T a, T... as> struct get<0, numeric_list<T, a, as...>> { constexpr static T value = a; };
116 
117 template<std::size_t n, typename T, T a, T... as> constexpr T array_get(const numeric_list<T, a, as...>&) {
118  return get<(int)n, numeric_list<T, a, as...>>::value;
119 }
120 
121 /* always get type, regardless of dummy; good for parameter pack expansion */
122 
123 template<typename T, T dummy, typename t> struct id_numeric { typedef t type; };
124 template<typename dummy, typename t> struct id_type { typedef t type; };
125 
126 /* equality checking, flagged version */
127 
128 template<typename a, typename b> struct is_same_gf : is_same<a, b> { constexpr static int global_flags = 0; };
129 
130 /* apply_op to list */
131 
132 template<
133  bool from_left, // false
134  template<typename, typename> class op,
135  typename additional_param,
136  typename... values
137 >
138 struct h_apply_op_helper { typedef type_list<typename op<values, additional_param>::type...> type; };
139 template<
140  template<typename, typename> class op,
141  typename additional_param,
142  typename... values
143 >
144 struct h_apply_op_helper<true, op, additional_param, values...> { typedef type_list<typename op<additional_param, values>::type...> type; };
145 
146 template<
147  bool from_left,
148  template<typename, typename> class op,
149  typename additional_param
150 >
151 struct h_apply_op
152 {
153  template<typename... values>
154  constexpr static typename h_apply_op_helper<from_left, op, additional_param, values...>::type helper(type_list<values...>)
155  { return typename h_apply_op_helper<from_left, op, additional_param, values...>::type(); }
156 };
157 
158 template<
159  template<typename, typename> class op,
160  typename additional_param,
161  typename a
162 >
163 struct apply_op_from_left { typedef decltype(h_apply_op<true, op, additional_param>::helper(a())) type; };
164 
165 template<
166  template<typename, typename> class op,
167  typename additional_param,
168  typename a
169 >
170 struct apply_op_from_right { typedef decltype(h_apply_op<false, op, additional_param>::helper(a())) type; };
171 
172 /* see if an element is in a list */
173 
174 template<
175  template<typename, typename> class test,
176  typename check_against,
177  typename h_list,
178  bool last_check_positive = false
179 >
180 struct contained_in_list;
181 
182 template<
183  template<typename, typename> class test,
184  typename check_against,
185  typename h_list
186 >
187 struct contained_in_list<test, check_against, h_list, true>
188 {
189  constexpr static bool value = true;
190 };
191 
192 template<
193  template<typename, typename> class test,
194  typename check_against,
195  typename a,
196  typename... as
197 >
198 struct contained_in_list<test, check_against, type_list<a, as...>, false> : contained_in_list<test, check_against, type_list<as...>, test<check_against, a>::value> {};
199 
200 template<
201  template<typename, typename> class test,
202  typename check_against,
203  typename... empty
204 >
205 struct contained_in_list<test, check_against, type_list<empty...>, false> { constexpr static bool value = false; };
206 
207 /* see if an element is in a list and check for global flags */
208 
209 template<
210  template<typename, typename> class test,
211  typename check_against,
212  typename h_list,
213  int default_flags = 0,
214  bool last_check_positive = false,
215  int last_check_flags = default_flags
216 >
217 struct contained_in_list_gf;
218 
219 template<
220  template<typename, typename> class test,
221  typename check_against,
222  typename h_list,
223  int default_flags,
224  int last_check_flags
225 >
226 struct contained_in_list_gf<test, check_against, h_list, default_flags, true, last_check_flags>
227 {
228  constexpr static bool value = true;
229  constexpr static int global_flags = last_check_flags;
230 };
231 
232 template<
233  template<typename, typename> class test,
234  typename check_against,
235  typename a,
236  typename... as,
237  int default_flags,
238  int last_check_flags
239 >
240 struct contained_in_list_gf<test, check_against, type_list<a, as...>, default_flags, false, last_check_flags> : contained_in_list_gf<test, check_against, type_list<as...>, default_flags, test<check_against, a>::value, test<check_against, a>::global_flags> {};
241 
242 template<
243  template<typename, typename> class test,
244  typename check_against,
245  typename... empty,
246  int default_flags,
247  int last_check_flags
248 >
249 struct contained_in_list_gf<test, check_against, type_list<empty...>, default_flags, false, last_check_flags> { constexpr static bool value = false; constexpr static int global_flags = default_flags; };
250 
251 /* generic reductions */
252 
253 template<
254  typename Reducer,
255  typename... Ts
256 > struct reduce;
257 
258 template<
259  typename Reducer
260 > struct reduce<Reducer>
261 {
262  EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE int run() { return Reducer::Identity; }
263 };
264 
265 template<
266  typename Reducer,
267  typename A
268 > struct reduce<Reducer, A>
269 {
270  EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE A run(A a) { return a; }
271 };
272 
273 template<
274  typename Reducer,
275  typename A,
276  typename... Ts
277 > struct reduce<Reducer, A, Ts...>
278 {
279  EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, Ts... ts) -> decltype(Reducer::run(a, reduce<Reducer, Ts...>::run(ts...))) {
280  return Reducer::run(a, reduce<Reducer, Ts...>::run(ts...));
281  }
282 };
283 
284 /* generic binary operations */
285 
286 struct sum_op {
287  template<typename A, typename B> EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a + b) { return a + b; }
288  static constexpr int Identity = 0;
289 };
290 struct product_op {
291  template<typename A, typename B> EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a * b) { return a * b; }
292  static constexpr int Identity = 1;
293 };
294 
295 struct logical_and_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a && b) { return a && b; } };
296 struct logical_or_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a || b) { return a || b; } };
297 
298 struct equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a == b) { return a == b; } };
299 struct not_equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a != b) { return a != b; } };
300 struct lesser_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a < b) { return a < b; } };
301 struct lesser_equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a <= b) { return a <= b; } };
302 struct greater_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a > b) { return a > b; } };
303 struct greater_equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a >= b) { return a >= b; } };
304 
305 /* generic unary operations */
306 
307 struct not_op { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(!a) { return !a; } };
308 struct negation_op { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(-a) { return -a; } };
309 struct greater_equal_zero_op { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(a >= 0) { return a >= 0; } };
310 
311 
312 /* reductions for lists */
313 
314 // using auto -> return value spec makes ICC 13.0 and 13.1 crash here, so we have to hack it
315 // together in front... (13.0 doesn't work with array_prod/array_reduce/... anyway, but 13.1
316 // does...
317 template<typename... Ts>
318 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE decltype(reduce<product_op, Ts...>::run((*((Ts*)0))...)) arg_prod(Ts... ts)
319 {
320  return reduce<product_op, Ts...>::run(ts...);
321 }
322 
323 template<typename... Ts>
324 constexpr EIGEN_STRONG_INLINE decltype(reduce<sum_op, Ts...>::run((*((Ts*)0))...)) arg_sum(Ts... ts)
325 {
326  return reduce<sum_op, Ts...>::run(ts...);
327 }
328 
329 /* reverse arrays */
330 
331 template<typename Array, int... n>
332 constexpr EIGEN_STRONG_INLINE Array h_array_reverse(Array arr, numeric_list<int, n...>)
333 {
334  return {{array_get<sizeof...(n) - n - 1>(arr)...}};
335 }
336 
337 template<typename T, std::size_t N>
338 constexpr EIGEN_STRONG_INLINE array<T, N> array_reverse(array<T, N> arr)
339 {
340  return h_array_reverse(arr, typename gen_numeric_list<int, N>::type());
341 }
342 
343 
344 /* generic array reductions */
345 
346 // can't reuse standard reduce() interface above because Intel's Compiler
347 // *really* doesn't like it, so we just reimplement the stuff
348 // (start from N - 1 and work down to 0 because specialization for
349 // n == N - 1 also doesn't work in Intel's compiler, so it goes into
350 // an infinite loop)
351 template<typename Reducer, typename T, std::size_t N, std::size_t n = N - 1>
352 struct h_array_reduce {
353  EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(array<T, N> arr, T identity) -> decltype(Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr)))
354  {
355  return Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr));
356  }
357 };
358 
359 template<typename Reducer, typename T, std::size_t N>
360 struct h_array_reduce<Reducer, T, N, 0>
361 {
362  EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array<T, N>& arr, T)
363  {
364  return array_get<0>(arr);
365  }
366 };
367 
368 template<typename Reducer, typename T>
369 struct h_array_reduce<Reducer, T, 0>
370 {
371  EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array<T, 0>&, T identity)
372  {
373  return identity;
374  }
375 };
376 
377 template<typename Reducer, typename T, std::size_t N>
378 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_reduce(const array<T, N>& arr, T identity) -> decltype(h_array_reduce<Reducer, T, N>::run(arr, identity))
379 {
380  return h_array_reduce<Reducer, T, N>::run(arr, identity);
381 }
382 
383 /* standard array reductions */
384 
385 template<typename T, std::size_t N>
386 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_sum(const array<T, N>& arr) -> decltype(array_reduce<sum_op, T, N>(arr, static_cast<T>(0)))
387 {
388  return array_reduce<sum_op, T, N>(arr, static_cast<T>(0));
389 }
390 
391 template<typename T, std::size_t N>
392 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_prod(const array<T, N>& arr) -> decltype(array_reduce<product_op, T, N>(arr, static_cast<T>(1)))
393 {
394  return array_reduce<product_op, T, N>(arr, static_cast<T>(1));
395 }
396 
397 template<typename t>
398 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(const std::vector<t>& a) {
399  eigen_assert(a.size() > 0);
400  t prod = 1;
401  for (size_t i = 0; i < a.size(); ++i) { prod *= a[i]; }
402  return prod;
403 }
404 
405 /* zip an array */
406 
407 template<typename Op, typename A, typename B, std::size_t N, int... n>
408 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A(), B())),N> h_array_zip(array<A, N> a, array<B, N> b, numeric_list<int, n...>)
409 {
410  return array<decltype(Op::run(A(), B())),N>{{ Op::run(array_get<n>(a), array_get<n>(b))... }};
411 }
412 
413 template<typename Op, typename A, typename B, std::size_t N>
414 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A(), B())),N> array_zip(array<A, N> a, array<B, N> b)
415 {
416  return h_array_zip<Op>(a, b, typename gen_numeric_list<int, N>::type());
417 }
418 
419 /* zip an array and reduce the result */
420 
421 template<typename Reducer, typename Op, typename A, typename B, std::size_t N, int... n>
422 constexpr EIGEN_STRONG_INLINE auto h_array_zip_and_reduce(array<A, N> a, array<B, N> b, numeric_list<int, n...>) -> decltype(reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A(), B()))>::type...>::run(Op::run(array_get<n>(a), array_get<n>(b))...))
423 {
424  return reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A(), B()))>::type...>::run(Op::run(array_get<n>(a), array_get<n>(b))...);
425 }
426 
427 template<typename Reducer, typename Op, typename A, typename B, std::size_t N>
428 constexpr EIGEN_STRONG_INLINE auto array_zip_and_reduce(array<A, N> a, array<B, N> b) -> decltype(h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b, typename gen_numeric_list<int, N>::type()))
429 {
430  return h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b, typename gen_numeric_list<int, N>::type());
431 }
432 
433 /* apply stuff to an array */
434 
435 template<typename Op, typename A, std::size_t N, int... n>
436 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A())),N> h_array_apply(array<A, N> a, numeric_list<int, n...>)
437 {
438  return array<decltype(Op::run(A())),N>{{ Op::run(array_get<n>(a))... }};
439 }
440 
441 template<typename Op, typename A, std::size_t N>
442 constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A())),N> array_apply(array<A, N> a)
443 {
444  return h_array_apply<Op>(a, typename gen_numeric_list<int, N>::type());
445 }
446 
447 /* apply stuff to an array and reduce */
448 
449 template<typename Reducer, typename Op, typename A, std::size_t N, int... n>
450 constexpr EIGEN_STRONG_INLINE auto h_array_apply_and_reduce(array<A, N> arr, numeric_list<int, n...>) -> decltype(reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A()))>::type...>::run(Op::run(array_get<n>(arr))...))
451 {
452  return reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A()))>::type...>::run(Op::run(array_get<n>(arr))...);
453 }
454 
455 template<typename Reducer, typename Op, typename A, std::size_t N>
456 constexpr EIGEN_STRONG_INLINE auto array_apply_and_reduce(array<A, N> a) -> decltype(h_array_apply_and_reduce<Reducer, Op, A, N>(a, typename gen_numeric_list<int, N>::type()))
457 {
458  return h_array_apply_and_reduce<Reducer, Op, A, N>(a, typename gen_numeric_list<int, N>::type());
459 }
460 
461 /* repeat a value n times (and make an array out of it
462  * usage:
463  * array<int, 16> = repeat<16>(42);
464  */
465 
466 template<int n>
467 struct h_repeat
468 {
469  template<typename t, int... ii>
470  constexpr static EIGEN_STRONG_INLINE array<t, n> run(t v, numeric_list<int, ii...>)
471  {
472  return {{ typename id_numeric<int, ii, t>::type(v)... }};
473  }
474 };
475 
476 template<int n, typename t>
477 constexpr array<t, n> repeat(t v) { return h_repeat<n>::run(v, typename gen_numeric_list<int, n>::type()); }
478 
479 /* instantiate a class by a C-style array */
480 template<class InstType, typename ArrType, std::size_t N, bool Reverse, typename... Ps>
481 struct h_instantiate_by_c_array;
482 
483 template<class InstType, typename ArrType, std::size_t N, typename... Ps>
484 struct h_instantiate_by_c_array<InstType, ArrType, N, false, Ps...>
485 {
486  static InstType run(ArrType* arr, Ps... args)
487  {
488  return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, Ps..., ArrType>::run(arr + 1, args..., arr[0]);
489  }
490 };
491 
492 template<class InstType, typename ArrType, std::size_t N, typename... Ps>
493 struct h_instantiate_by_c_array<InstType, ArrType, N, true, Ps...>
494 {
495  static InstType run(ArrType* arr, Ps... args)
496  {
497  return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, ArrType, Ps...>::run(arr + 1, arr[0], args...);
498  }
499 };
500 
501 template<class InstType, typename ArrType, typename... Ps>
502 struct h_instantiate_by_c_array<InstType, ArrType, 0, false, Ps...>
503 {
504  static InstType run(ArrType* arr, Ps... args)
505  {
506  (void)arr;
507  return InstType(args...);
508  }
509 };
510 
511 template<class InstType, typename ArrType, typename... Ps>
512 struct h_instantiate_by_c_array<InstType, ArrType, 0, true, Ps...>
513 {
514  static InstType run(ArrType* arr, Ps... args)
515  {
516  (void)arr;
517  return InstType(args...);
518  }
519 };
520 
521 template<class InstType, typename ArrType, std::size_t N, bool Reverse = false>
522 InstType instantiate_by_c_array(ArrType* arr)
523 {
524  return h_instantiate_by_c_array<InstType, ArrType, N, Reverse>::run(arr);
525 }
526 
527 } // end namespace internal
528 
529 } // end namespace Eigen
530 
531 #endif // EIGEN_MOREMETA_H
Array< int, Dynamic, 1 > v
Array< int, 3, 1 > b
int n
MatrixXcf A
MatrixXf B
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define eigen_assert(x)
Definition: Macros.h:902
float * p
Eigen::Triplet< double > T
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:49
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:67
constexpr auto array_apply_and_reduce(array< A, N > a) -> decltype(h_array_apply_and_reduce< Reducer, Op, A, N >(a, typename gen_numeric_list< int, N >::type()))
Definition: MoreMeta.h:456
constexpr array< T, N > array_reverse(array< T, N > arr)
Definition: MoreMeta.h:338
constexpr Array h_array_reverse(Array arr, numeric_list< int, n... >)
Definition: MoreMeta.h:332
constexpr auto h_array_zip_and_reduce(array< A, N > a, array< B, N > b, numeric_list< int, n... >) -> decltype(reduce< Reducer, typename id_numeric< int, n, decltype(Op::run(A(), B()))>::type... >::run(Op::run(array_get< n >(a), array_get< n >(b))...))
Definition: MoreMeta.h:422
constexpr decltype(reduce< sum_op, Ts... >::run((*((Ts *) 0))...) arg_sum)(Ts... ts)
Definition: MoreMeta.h:324
constexpr array< decltype(Op::run(A())), N > h_array_apply(array< A, N > a, numeric_list< int, n... >)
Definition: MoreMeta.h:436
constexpr T & array_get(std::array< T, N > &a)
Definition: EmulateArray.h:275
constexpr array< t, n > repeat(t v)
Definition: MoreMeta.h:477
constexpr auto h_array_apply_and_reduce(array< A, N > arr, numeric_list< int, n... >) -> decltype(reduce< Reducer, typename id_numeric< int, n, decltype(Op::run(A()))>::type... >::run(Op::run(array_get< n >(arr))...))
Definition: MoreMeta.h:450
constexpr auto array_reduce(const array< T, N > &arr, T identity) -> decltype(h_array_reduce< Reducer, T, N >::run(arr, identity))
Definition: MoreMeta.h:378
constexpr auto array_sum(const array< T, N > &arr) -> decltype(array_reduce< sum_op, T, N >(arr, static_cast< T >(0)))
Definition: MoreMeta.h:386
constexpr decltype(reduce< product_op, Ts... >::run((*((Ts *) 0))...) arg_prod)(Ts... ts)
Definition: MoreMeta.h:318
constexpr auto array_prod(const array< T, N > &arr) -> decltype(array_reduce< product_op, T, N >(arr, static_cast< T >(1)))
Definition: MoreMeta.h:392
constexpr array< decltype(Op::run(A(), B())), N > h_array_zip(array< A, N > a, array< B, N > b, numeric_list< int, n... >)
Definition: MoreMeta.h:408
InstType instantiate_by_c_array(ArrType *arr)
Definition: MoreMeta.h:522
constexpr auto array_zip_and_reduce(array< A, N > a, array< B, N > b) -> decltype(h_array_zip_and_reduce< Reducer, Op, A, B, N >(a, b, typename gen_numeric_list< int, N >::type()))
Definition: MoreMeta.h:428
constexpr array< decltype(Op::run(A(), B())), N > array_zip(array< A, N > a, array< B, N > b)
Definition: MoreMeta.h:414
constexpr array< decltype(Op::run(A())), N > array_apply(array< A, N > a)
Definition: MoreMeta.h:442
: InteropHeaders
Definition: Core:139
std::array< T, N > array
Definition: EmulateArray.h:256