11#ifndef EIGEN_MOREMETA_H
12#define EIGEN_MOREMETA_H
15#include "../InternalHeaderCheck.h"
21template <
typename... tt>
23 constexpr static int count =
sizeof...(tt);
26template <
typename t,
typename... tt>
27struct type_list<t, tt...> {
28 constexpr static int count =
sizeof...(tt) + 1;
32template <
typename T, T... nn>
34 constexpr static std::size_t count =
sizeof...(nn);
37template <
typename T, T n, T... nn>
38struct numeric_list<T, n, nn...> {
39 static constexpr std::size_t count =
sizeof...(nn) + 1;
40 static constexpr T first_value = n;
43#ifndef EIGEN_PARSED_BY_DOXYGEN
54template <
typename T, std::size_t n, T start = 0, T... ii>
55struct gen_numeric_list : gen_numeric_list<T, n - 1, start, start + n - 1, ii...> {};
56template <
typename T, T start, T... ii>
57struct gen_numeric_list<T, 0, start, ii...> {
58 typedef numeric_list<T, ii...> type;
61template <
typename T, std::size_t n, T start = 0, T... ii>
62struct gen_numeric_list_reversed : gen_numeric_list_reversed<T, n - 1, start, ii..., start + n - 1> {};
63template <
typename T, T start, T... ii>
64struct gen_numeric_list_reversed<T, 0, start, ii...> {
65 typedef numeric_list<T, ii...> type;
68template <
typename T, std::size_t n, T a, T b, T start = 0, T... ii>
69struct gen_numeric_list_swapped_pair
70 : gen_numeric_list_swapped_pair<T, n - 1, a, b, start,
71 (start + n - 1) == a ? b : ((start + n - 1) == b ? a : (start + n - 1)), ii...> {};
72template <
typename T, T a, T b, T start, T... ii>
73struct gen_numeric_list_swapped_pair<T, 0, a, b, start, ii...> {
74 typedef numeric_list<T, ii...> type;
77template <
typename T, std::size_t n, T V, T... nn>
78struct gen_numeric_list_repeated : gen_numeric_list_repeated<T, n - 1, V, V, nn...> {};
79template <
typename T, T V, T... nn>
80struct gen_numeric_list_repeated<T, 0, V, nn...> {
81 typedef numeric_list<T, nn...> type;
86template <
class a,
class b>
89template <
typename... as,
typename... bs>
90struct concat<type_list<as...>, type_list<bs...>> {
91 typedef type_list<as..., bs...> type;
93template <
typename T, T... as, T... bs>
94struct concat<numeric_list<T, as...>, numeric_list<T, bs...>> {
95 typedef numeric_list<T, as..., bs...> type;
98template <
typename... p>
104template <
typename a,
typename b>
105struct mconcat<a, b> : concat<a, b> {};
106template <
typename a,
typename b,
typename... cs>
107struct mconcat<a, b, cs...> : concat<a, typename mconcat<b, cs...>::type> {};
111template <
int n,
typename x>
113template <
int n,
typename a,
typename... as>
114struct take<n, type_list<a, as...>> : concat<type_list<a>, typename take<n - 1, type_list<as...>>::type> {};
116struct take<n, type_list<>> {
117 typedef type_list<> type;
119template <
typename a,
typename... as>
120struct take<0, type_list<a, as...>> {
121 typedef type_list<> type;
124struct take<0, type_list<>> {
125 typedef type_list<> type;
128template <
typename T,
int n, T a, T... as>
129struct take<n, numeric_list<T, a, as...>>
130 : concat<numeric_list<T, a>, typename take<n - 1, numeric_list<T, as...>>::type> {};
134template <
typename T, T a, T... as>
135struct take<0, numeric_list<T, a, as...>> {
136 typedef numeric_list<T> type;
139struct take<0, numeric_list<T>> {
140 typedef numeric_list<T> type;
143template <
typename T,
int n, T... ii>
144struct h_skip_helper_numeric;
145template <
typename T,
int n, T i, T... ii>
146struct h_skip_helper_numeric<T, n, i, ii...> : h_skip_helper_numeric<T, n - 1, ii...> {};
147template <
typename T, T i, T... ii>
148struct h_skip_helper_numeric<T, 0, i, ii...> {
149 typedef numeric_list<T, i, ii...> type;
151template <
typename T,
int n>
152struct h_skip_helper_numeric<T, n> {
153 typedef numeric_list<T> type;
156struct h_skip_helper_numeric<T, 0> {
157 typedef numeric_list<T> type;
160template <
int n,
typename... tt>
161struct h_skip_helper_type;
162template <
int n,
typename t,
typename... tt>
163struct h_skip_helper_type<n, t, tt...> : h_skip_helper_type<n - 1, tt...> {};
164template <
typename t,
typename... tt>
165struct h_skip_helper_type<0, t, tt...> {
166 typedef type_list<t, tt...> type;
169struct h_skip_helper_type<n> {
170 typedef type_list<> type;
173struct h_skip_helper_type<0> {
174 typedef type_list<> type;
180 template <
typename T, T... ii>
181 constexpr static EIGEN_STRONG_INLINE
typename h_skip_helper_numeric<T, n, ii...>::type helper(
182 numeric_list<T, ii...>) {
183 return typename h_skip_helper_numeric<T, n, ii...>::type();
185 template <
typename... tt>
186 constexpr static EIGEN_STRONG_INLINE
typename h_skip_helper_type<n, tt...>::type helper(type_list<tt...>) {
187 return typename h_skip_helper_type<n, tt...>::type();
191template <
int n,
typename a>
193 typedef decltype(h_skip<n>::helper(a())) type;
196template <
int start,
int count,
typename a>
197struct slice : take<count, typename skip<start, a>::type> {};
201template <
int n,
typename x>
204template <
int n,
typename a,
typename... as>
205struct get<n, type_list<a, as...>> : get<n - 1, type_list<as...>> {};
206template <
typename a,
typename... as>
207struct get<0, type_list<a, as...>> {
211template <
typename T,
int n, T a, T... as>
212struct get<n, numeric_list<T, a, as...>> : get<n - 1, numeric_list<T, as...>> {};
213template <
typename T, T a, T... as>
214struct get<0, numeric_list<T, a, as...>> {
215 constexpr static T value = a;
218template <std::size_t n,
typename T, T a, T... as>
219constexpr T array_get(
const numeric_list<T, a, as...>&) {
220 return get<(int)n, numeric_list<T, a, as...>>::value;
225template <
typename T, T dummy,
typename t>
229template <
typename dummy,
typename t>
236template <
typename a,
typename b>
237struct is_same_gf : is_same<a, b> {
238 constexpr static int global_flags = 0;
243template <
bool from_left,
244 template <
typename,
typename>
class op,
typename additional_param,
typename... values>
245struct h_apply_op_helper {
246 typedef type_list<typename op<values, additional_param>::type...> type;
248template <
template <
typename,
typename>
class op,
typename additional_param,
typename... values>
249struct h_apply_op_helper<true, op, additional_param, values...> {
250 typedef type_list<typename op<additional_param, values>::type...> type;
253template <
bool from_left,
template <
typename,
typename>
class op,
typename additional_param>
255 template <
typename... values>
256 constexpr static typename h_apply_op_helper<from_left, op, additional_param, values...>::type helper(
257 type_list<values...>) {
258 return typename h_apply_op_helper<from_left, op, additional_param, values...>::type();
262template <
template <
typename,
typename>
class op,
typename additional_param,
typename a>
263struct apply_op_from_left {
264 typedef decltype(h_apply_op<true, op, additional_param>::helper(a())) type;
267template <
template <
typename,
typename>
class op,
typename additional_param,
typename a>
268struct apply_op_from_right {
269 typedef decltype(h_apply_op<false, op, additional_param>::helper(a())) type;
274template <
template <
typename,
typename>
class test,
typename check_against,
typename h_list,
275 bool last_check_positive =
false>
276struct contained_in_list;
278template <
template <
typename,
typename>
class test,
typename check_against,
typename h_list>
279struct contained_in_list<test, check_against, h_list, true> {
280 constexpr static bool value =
true;
283template <
template <
typename,
typename>
class test,
typename check_against,
typename a,
typename... as>
284struct contained_in_list<test, check_against, type_list<a, as...>, false>
285 : contained_in_list<test, check_against, type_list<as...>, test<check_against, a>::value> {};
287template <
template <
typename,
typename>
class test,
typename check_against,
typename... empty>
288struct contained_in_list<test, check_against, type_list<empty...>, false> {
289 constexpr static bool value =
false;
294template <
template <
typename,
typename>
class test,
typename check_against,
typename h_list,
int default_flags = 0,
295 bool last_check_positive =
false,
int last_check_flags = default_flags>
296struct contained_in_list_gf;
298template <
template <
typename,
typename>
class test,
typename check_against,
typename h_list,
int default_flags,
299 int last_check_flags>
300struct contained_in_list_gf<test, check_against, h_list, default_flags, true, last_check_flags> {
301 constexpr static bool value =
true;
302 constexpr static int global_flags = last_check_flags;
305template <
template <
typename,
typename>
class test,
typename check_against,
typename a,
typename... as,
306 int default_flags,
int last_check_flags>
307struct contained_in_list_gf<test, check_against, type_list<a, as...>, default_flags, false, last_check_flags>
308 : contained_in_list_gf<test, check_against, type_list<as...>, default_flags, test<check_against, a>::value,
309 test<check_against, a>::global_flags> {};
311template <
template <
typename,
typename>
class test,
typename check_against,
typename... empty,
int default_flags,
312 int last_check_flags>
313struct contained_in_list_gf<test, check_against, type_list<empty...>, default_flags, false, last_check_flags> {
314 constexpr static bool value =
false;
315 constexpr static int global_flags = default_flags;
320template <
typename Reducer,
typename... Ts>
323template <
typename Reducer>
324struct reduce<Reducer> {
325 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE
int run() {
return Reducer::Identity; }
328template <
typename Reducer,
typename A>
329struct reduce<Reducer, A> {
330 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE A run(A a) {
return a; }
333template <
typename Reducer,
typename A,
typename... Ts>
334struct reduce<Reducer, A, Ts...> {
335 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE
auto run(A a, Ts... ts)
336 ->
decltype(Reducer::run(a, reduce<Reducer, Ts...>::run(ts...))) {
337 return Reducer::run(a, reduce<Reducer, Ts...>::run(ts...));
344 template <
typename A,
typename B>
345 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a + b) {
348 static constexpr int Identity = 0;
351 template <
typename A,
typename B>
352 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a * b) {
355 static constexpr int Identity = 1;
358struct logical_and_op {
359 template <
typename A,
typename B>
360 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a && b) {
364struct logical_or_op {
365 template <
typename A,
typename B>
366 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a || b) {
372 template <
typename A,
typename B>
373 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a == b) {
378 template <
typename A,
typename B>
379 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a != b) {
384 template <
typename A,
typename B>
385 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a < b) {
389struct lesser_equal_op {
390 template <
typename A,
typename B>
391 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a <= b) {
396 template <
typename A,
typename B>
397 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a > b) {
401struct greater_equal_op {
402 template <
typename A,
typename B>
403 constexpr static EIGEN_STRONG_INLINE
auto run(A a, B b) ->
decltype(a >= b) {
411 template <
typename A>
412 constexpr static EIGEN_STRONG_INLINE
auto run(A a) ->
decltype(!a) {
417 template <
typename A>
418 constexpr static EIGEN_STRONG_INLINE
auto run(A a) ->
decltype(-a) {
422struct greater_equal_zero_op {
423 template <
typename A>
424 constexpr static EIGEN_STRONG_INLINE
auto run(A a) ->
decltype(a >= 0) {
434template <
typename... Ts>
435EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
decltype(reduce<product_op, Ts...>::run((*((Ts*)0))...)) arg_prod(
437 return reduce<product_op, Ts...>::run(ts...);
440template <
typename... Ts>
441constexpr EIGEN_STRONG_INLINE
decltype(reduce<sum_op, Ts...>::run((*((Ts*)0))...)) arg_sum(Ts... ts) {
442 return reduce<sum_op, Ts...>::run(ts...);
447template <
typename Array,
int... n>
448constexpr EIGEN_STRONG_INLINE Array h_array_reverse(Array arr, numeric_list<int, n...>) {
449 return {{array_get<
sizeof...(n) - n - 1>(arr)...}};
452template <
typename T, std::
size_t N>
453constexpr EIGEN_STRONG_INLINE array<T, N> array_reverse(array<T, N> arr) {
454 return h_array_reverse(arr,
typename gen_numeric_list<int, N>::type());
464template <
typename Reducer,
typename T, std::size_t N, std::size_t n = N - 1>
465struct h_array_reduce {
466 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE
auto run(array<T, N> arr, T identity)
467 ->
decltype(Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr))) {
468 return Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr));
472template <
typename Reducer,
typename T, std::
size_t N>
473struct h_array_reduce<Reducer, T, N, 0> {
474 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE T run(
const array<T, N>& arr, T) {
return array_get<0>(arr); }
477template <
typename Reducer,
typename T>
478struct h_array_reduce<Reducer, T, 0> {
479 EIGEN_DEVICE_FUNC
constexpr static EIGEN_STRONG_INLINE T run(
const array<T, 0>&, T identity) {
return identity; }
482template <
typename Reducer,
typename T, std::
size_t N>
483EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
auto array_reduce(
const array<T, N>& arr, T identity)
484 ->
decltype(h_array_reduce<Reducer, T, N>::run(arr, identity)) {
485 return h_array_reduce<Reducer, T, N>::run(arr, identity);
490template <
typename T, std::
size_t N>
491EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
auto array_sum(
const array<T, N>& arr)
492 ->
decltype(array_reduce<sum_op, T, N>(arr,
static_cast<T
>(0))) {
493 return array_reduce<sum_op, T, N>(arr,
static_cast<T
>(0));
496template <
typename T, std::
size_t N>
497EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
auto array_prod(
const array<T, N>& arr)
498 ->
decltype(array_reduce<product_op, T, N>(arr,
static_cast<T
>(1))) {
499 return array_reduce<product_op, T, N>(arr,
static_cast<T
>(1));
503EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(
const std::vector<t>& a) {
504 eigen_assert(a.size() > 0);
506 for (
size_t i = 0; i < a.size(); ++i) {
514template <
typename Op,
typename A,
typename B, std::size_t N,
int... n>
515constexpr EIGEN_STRONG_INLINE array<
decltype(Op::run(A(), B())), N> h_array_zip(array<A, N> a, array<B, N> b,
516 numeric_list<int, n...>) {
517 return array<
decltype(Op::run(A(), B())), N>{{Op::run(array_get<n>(a), array_get<n>(b))...}};
520template <
typename Op,
typename A,
typename B, std::
size_t N>
521constexpr EIGEN_STRONG_INLINE array<
decltype(Op::run(A(), B())), N> array_zip(array<A, N> a, array<B, N> b) {
522 return h_array_zip<Op>(a, b,
typename gen_numeric_list<int, N>::type());
527template <
typename Reducer,
typename Op,
typename A,
typename B, std::size_t N,
int... n>
528constexpr EIGEN_STRONG_INLINE
auto h_array_zip_and_reduce(array<A, N> a, array<B, N> b, numeric_list<int, n...>)
529 ->
decltype(reduce<Reducer,
typename id_numeric<int, n,
decltype(Op::run(A(), B()))>::type...>::run(
530 Op::run(array_get<n>(a), array_get<n>(b))...)) {
531 return reduce<Reducer,
typename id_numeric<int, n,
decltype(Op::run(A(), B()))>::type...>::run(
532 Op::run(array_get<n>(a), array_get<n>(b))...);
535template <
typename Reducer,
typename Op,
typename A,
typename B, std::
size_t N>
536constexpr EIGEN_STRONG_INLINE
auto array_zip_and_reduce(array<A, N> a, array<B, N> b)
537 ->
decltype(h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b,
typename gen_numeric_list<int, N>::type())) {
538 return h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b,
typename gen_numeric_list<int, N>::type());
543template <
typename Op,
typename A, std::size_t N,
int... n>
544constexpr EIGEN_STRONG_INLINE array<
decltype(Op::run(A())), N> h_array_apply(array<A, N> a, numeric_list<int, n...>) {
545 return array<
decltype(Op::run(A())), N>{{Op::run(array_get<n>(a))...}};
548template <
typename Op,
typename A, std::
size_t N>
549constexpr EIGEN_STRONG_INLINE array<
decltype(Op::run(A())), N> array_apply(array<A, N> a) {
550 return h_array_apply<Op>(a,
typename gen_numeric_list<int, N>::type());
555template <
typename Reducer,
typename Op,
typename A, std::size_t N,
int... n>
556constexpr EIGEN_STRONG_INLINE
auto h_array_apply_and_reduce(array<A, N> arr, numeric_list<int, n...>)
557 ->
decltype(reduce<Reducer,
typename id_numeric<int, n,
decltype(Op::run(A()))>::type...>::run(
558 Op::run(array_get<n>(arr))...)) {
559 return reduce<Reducer,
typename id_numeric<int, n,
decltype(Op::run(A()))>::type...>::run(
560 Op::run(array_get<n>(arr))...);
563template <
typename Reducer,
typename Op,
typename A, std::
size_t N>
564constexpr EIGEN_STRONG_INLINE
auto array_apply_and_reduce(array<A, N> a)
565 ->
decltype(h_array_apply_and_reduce<Reducer, Op, A, N>(a,
typename gen_numeric_list<int, N>::type())) {
566 return h_array_apply_and_reduce<Reducer, Op, A, N>(a,
typename gen_numeric_list<int, N>::type());
576 template <
typename t,
int... ii>
577 constexpr static EIGEN_STRONG_INLINE array<t, n> run(t v, numeric_list<int, ii...>) {
578 return {{
typename id_numeric<int, ii, t>::type(v)...}};
582template <
int n,
typename t>
583constexpr array<t, n> repeat(t v) {
584 return h_repeat<n>::run(v,
typename gen_numeric_list<int, n>::type());
588template <
class InstType,
typename ArrType, std::size_t N,
bool Reverse,
typename... Ps>
589struct h_instantiate_by_c_array;
591template <
class InstType,
typename ArrType, std::size_t N,
typename... Ps>
592struct h_instantiate_by_c_array<InstType, ArrType, N, false, Ps...> {
593 static InstType run(ArrType* arr, Ps... args) {
594 return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, Ps..., ArrType>::run(arr + 1, args..., arr[0]);
598template <
class InstType,
typename ArrType, std::size_t N,
typename... Ps>
599struct h_instantiate_by_c_array<InstType, ArrType, N, true, Ps...> {
600 static InstType run(ArrType* arr, Ps... args) {
601 return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, ArrType, Ps...>::run(arr + 1, arr[0], args...);
605template <
class InstType,
typename ArrType,
typename... Ps>
606struct h_instantiate_by_c_array<InstType, ArrType, 0, false, Ps...> {
607 static InstType run(ArrType* arr, Ps... args) {
609 return InstType(args...);
613template <
class InstType,
typename ArrType,
typename... Ps>
614struct h_instantiate_by_c_array<InstType, ArrType, 0, true, Ps...> {
615 static InstType run(ArrType* arr, Ps... args) {
617 return InstType(args...);
621template <
class InstType,
typename ArrType, std::
size_t N,
bool Reverse = false>
622InstType instantiate_by_c_array(ArrType* arr) {
623 return h_instantiate_by_c_array<InstType, ArrType, N, Reverse>::run(arr);
Namespace containing all symbols from the Eigen library.
Definition Core:137