10 #ifndef EIGEN_CXX11META_H 11 #define EIGEN_CXX11META_H 19 #if __cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900 33 template<
typename... tt>
36 template<
typename t,
typename... tt>
37 struct type_list<
t, tt...> { constexpr
static int count =
sizeof...(tt) + 1;
typedef t first_type; };
39 template<
typename T,
T...
nn>
42 template<
typename T,
T n,
T...
nn>
43 struct numeric_list<
T, n,
nn...> { constexpr
static std::size_t count =
sizeof...(nn) + 1; constexpr
static T first_value =
n; };
55 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...> {};
56 template<
typename T,
T start,
T... ii>
struct gen_numeric_list<
T, 0, start, ii...> {
typedef numeric_list<
T, ii...>
type; };
58 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> {};
59 template<
typename T,
T start,
T... ii>
struct gen_numeric_list_reversed<
T, 0, start, ii...> {
typedef numeric_list<
T, ii...>
type; };
61 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...> {};
62 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; };
64 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...> {};
65 template<
typename T,
T V,
T...
nn>
struct gen_numeric_list_repeated<
T, 0, V,
nn...> {
typedef numeric_list<
T,
nn...>
type; };
69 template<
class a,
class b>
struct concat;
72 template<
typename T,
T... as,
T... bs>
struct concat<numeric_list<
T, as...>, numeric_list<
T, bs...> > {
typedef numeric_list<
T, as..., bs...>
type; };
74 template<
typename...
p>
struct mconcat;
75 template<
typename a>
struct mconcat<a> {
typedef a
type; };
76 template<
typename a,
typename b>
struct mconcat<a, b> :
concat<a, b> {};
77 template<
typename a,
typename b,
typename... cs>
struct mconcat<a, b, cs...> :
concat<a, typename mconcat<b, cs...>::type> {};
81 template<
int n,
typename x>
struct take;
82 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> {};
87 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> {};
88 template<
typename T,
int n>
struct take<n, numeric_list<
T>> {
typedef numeric_list<T>
type; };
89 template<
typename T,
T a,
T... as>
struct take<0, numeric_list<
T, a, as...>> {
typedef numeric_list<T>
type; };
90 template<
typename T>
struct take<0, numeric_list<
T>> {
typedef numeric_list<T>
type; };
92 template<
typename T,
int n,
T... ii>
struct h_skip_helper_numeric;
93 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...> {};
94 template<
typename T, T
i, T... ii>
struct h_skip_helper_numeric<T, 0, i, ii...> {
typedef numeric_list<
T,
i, ii...>
type; };
95 template<
typename T,
int n>
struct h_skip_helper_numeric<T, n> {
typedef numeric_list<T>
type; };
96 template<
typename T>
struct h_skip_helper_numeric<T, 0> {
typedef numeric_list<T>
type; };
98 template<
int n,
typename... tt>
struct h_skip_helper_type;
99 template<
int n,
typename t,
typename... tt>
struct h_skip_helper_type<n, t, tt...> : h_skip_helper_type<n-1, tt...> {};
100 template<
typename t,
typename... tt>
struct h_skip_helper_type<0, t, tt...> {
typedef type_list<
t, tt...>
type; };
101 template<
int n>
struct h_skip_helper_type<n> {
typedef type_list<> type; };
106 template<
typename T, T... ii>
108 template<
typename... tt>
112 template<
int n,
typename a>
struct skip {
typedef decltype(h_skip<n>::helper(
a()))
type; };
114 template<
int start,
int count, typename a> struct
slice : take<count, typename skip<start, a>::
type> {};
118 template<
int n,
typename x>
struct get;
120 template<
int n,
typename a,
typename... as>
struct get<n,
type_list<a, as...>> :
get<n-1, type_list<as...>> {};
121 template<
typename a,
typename... as>
struct get<0,
type_list<a, as...>> {
typedef a
type; };
123 template<
typename T,
int n, T
a, T... as>
struct get<n, numeric_list<T, a, as...>> :
get<n-1, numeric_list<T, as...>> {};
124 template<
typename T, T
a, T... as>
struct get<0, numeric_list<T, a, as...>> { constexpr
static T
value =
a; };
128 template<
typename T, T dummy,
typename t>
struct id_numeric {
typedef t
type; };
129 template<
typename dummy,
typename t>
struct id_type {
typedef t
type; };
133 template<
typename a,
typename b>
struct is_same_gf : is_same<a, b> { constexpr
static int global_flags = 0; };
139 template<
typename,
typename>
class op,
140 typename additional_param,
145 template<
typename,
typename>
class op,
146 typename additional_param,
153 template<
typename,
typename>
class op,
154 typename additional_param
158 template<
typename...
values>
164 template<
typename,
typename>
class op,
165 typename additional_param,
168 struct apply_op_from_left {
typedef decltype(h_apply_op<true, op, additional_param>::helper(
a()))
type; };
171 template<typename, typename> class op,
172 typename additional_param,
175 struct apply_op_from_right {
typedef decltype(h_apply_op<false, op, additional_param>::helper(
a()))
type; };
180 template<typename, typename> class
test,
181 typename check_against,
183 bool last_check_positive = false
185 struct contained_in_list;
188 template<typename, typename> class test,
189 typename check_against,
192 struct contained_in_list<test, check_against, h_list, true>
194 constexpr
static bool value =
true;
198 template<
typename,
typename>
class test,
199 typename check_against,
203 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> {};
206 template<
typename,
typename>
class test,
207 typename check_against
215 template<
typename,
typename>
class test,
216 typename check_against,
218 int default_flags = 0,
219 bool last_check_positive =
false,
220 int last_check_flags = default_flags
222 struct contained_in_list_gf;
225 template<
typename,
typename>
class test,
226 typename check_against,
231 struct contained_in_list_gf<test, check_against, h_list, default_flags, true, last_check_flags>
233 constexpr
static bool value =
true;
234 constexpr
static int global_flags = last_check_flags;
238 template<
typename,
typename>
class test,
239 typename check_against,
245 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> {};
248 template<
typename,
typename>
class test,
249 typename check_against
254 struct contained_in_list_gf<test, check_against,
type_list<
EIGEN_TPL_PP_SPEC_HACK_USE(
empty)>, default_flags, false, last_check_flags> { constexpr
static bool value =
false; constexpr
static int global_flags = default_flags; };
265 >
struct reduce<Reducer>
267 constexpr
static inline int run() {
return Reducer::Identity; }
273 >
struct reduce<Reducer,
A>
275 constexpr
static inline A run(
A a) {
return a; }
282 >
struct reduce<Reducer, A, Ts...>
292 template<
typename A,
typename B> EIGEN_DEVICE_FUNC constexpr
static inline auto run(A a,
B b) -> decltype(a + b) {
return a +
b; }
293 static constexpr
int Identity = 0;
296 template<
typename A,
typename B> EIGEN_DEVICE_FUNC constexpr
static inline auto run(A a,
B b) -> decltype(a * b) {
return a *
b; }
297 static constexpr
int Identity = 1;
300 struct logical_and_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a && b) {
return a &&
b; } };
301 struct logical_or_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a || b) {
return a ||
b; } };
303 struct equal_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a == b) {
return a ==
b; } };
304 struct not_equal_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a != b) {
return a !=
b; } };
305 struct lesser_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a < b) {
return a <
b; } };
306 struct lesser_equal_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a <= b) {
return a <=
b; } };
307 struct greater_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a > b) {
return a >
b; } };
308 struct greater_equal_op {
template<
typename A,
typename B> constexpr
static inline auto run(A a,
B b) -> decltype(a >= b) {
return a >=
b; } };
312 struct not_op {
template<
typename A> constexpr
static inline auto run(A a) -> decltype(!a) {
return !
a; } };
313 struct negation_op {
template<
typename A> constexpr
static inline auto run(A a) -> decltype(-a) {
return -
a; } };
314 struct greater_equal_zero_op {
template<
typename A> constexpr
static inline auto run(A a) -> decltype(a >= 0) {
return a >= 0; } };
322 template<
typename... Ts>
328 template<
typename... Ts>
336 template<
typename Array,
int... n>
337 constexpr
inline Array h_array_reverse(Array
arr, numeric_list<int, n...>)
339 return {{
array_get<
sizeof...(n) - n - 1>(arr)...}};
342 template<
typename T, std::
size_t N>
357 struct h_array_reduce {
364 template<
typename Reducer,
typename T, std::
size_t N>
365 struct h_array_reduce<Reducer, T, N, 0>
367 EIGEN_DEVICE_FUNC constexpr
static inline T
run(
const array<T, N>& arr, T)
369 return array_get<0>(
arr);
373 template<
typename Reducer,
typename T>
374 struct h_array_reduce<Reducer, T, 0>
376 EIGEN_DEVICE_FUNC constexpr
static inline T
run(
const array<T, 0>&, T identity)
382 template<
typename Reducer,
typename T, std::
size_t N>
390 template<
typename T, std::
size_t N>
391 EIGEN_DEVICE_FUNC constexpr
inline auto array_sum(
const array<T, N>& arr) -> decltype(array_reduce<sum_op, T, N>(arr, static_cast<T>(0)))
393 return array_reduce<sum_op, T, N>(
arr,
static_cast<T
>(0));
396 template<
typename T, std::
size_t N>
397 EIGEN_DEVICE_FUNC constexpr
inline auto array_prod(
const array<T, N>& arr) -> decltype(array_reduce<product_op, T, N>(arr, static_cast<T>(1)))
399 return array_reduce<product_op, T, N>(
arr,
static_cast<T
>(1));
406 for (
size_t i = 0; i < a.size(); ++
i) { prod *= a[
i]; }
412 template<
typename Op,
typename A,
typename B,
std::size_t N,
int... n>
418 template<
typename Op,
typename A,
typename B, std::
size_t N>
426 template<
typename Reducer,
typename Op,
typename A,
typename B,
std::size_t N,
int... n>
427 constexpr
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))...))
432 template<
typename Reducer,
typename Op,
typename A,
typename B, std::
size_t N>
433 constexpr
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()))
440 template<
typename Op,
typename A,
std::size_t N,
int... n>
446 template<
typename Op,
typename A, std::
size_t N>
454 template<
typename Reducer,
typename Op,
typename A,
std::size_t N,
int... n>
455 constexpr
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))...))
460 template<
typename Reducer,
typename Op,
typename A, std::
size_t N>
474 template<
typename t,
int... ii>
481 template<
int n,
typename t>
485 template<
class InstType,
typename ArrType,
std::size_t N,
bool Reverse,
typename... Ps>
486 struct h_instantiate_by_c_array;
488 template<
class InstType,
typename ArrType,
std::size_t N,
typename... Ps>
489 struct h_instantiate_by_c_array<InstType, ArrType, N, false, Ps...>
491 static InstType
run(ArrType* arr, Ps...
args)
497 template<
class InstType,
typename ArrType,
std::size_t N,
typename... Ps>
498 struct h_instantiate_by_c_array<InstType, ArrType, N, true, Ps...>
500 static InstType
run(ArrType* arr, Ps...
args)
506 template<
class InstType,
typename ArrType,
typename... Ps>
507 struct h_instantiate_by_c_array<InstType, ArrType, 0, false, Ps...>
509 static InstType
run(ArrType* arr, Ps...
args)
512 return InstType(
args...);
516 template<
class InstType,
typename ArrType,
typename... Ps>
517 struct h_instantiate_by_c_array<InstType, ArrType, 0, true, Ps...>
519 static InstType
run(ArrType* arr, Ps...
args)
522 return InstType(
args...);
526 template<
class InstType,
typename ArrType, std::
size_t N,
bool Reverse = false>
527 InstType instantiate_by_c_array(ArrType* arr)
536 #else // Non C++11, fallback to emulation mode 542 #endif // EIGEN_CXX11META_H Helper template which holds a list of types.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
#define EIGEN_STRONG_INLINE
array< t, n > repeat(t v)
Namespace containing all symbols from the Eigen library.
static const std::size_t count
bool array_apply_and_reduce(const array< A, N > &a)
Eigen::Triplet< double > T
constexpr descr< 0 > concat()
#define EIGEN_TPL_PP_SPEC_HACK_DEFC(mt, n)
bool array_zip_and_reduce(const array< A, N > &a, const array< B, N > &b)
#define EIGEN_TPL_PP_SPEC_HACK_USE(n)
const Index array_get(DimensionList< Index, Rank > &)
void test(OptionalJacobian< 2, 3 > H=boost::none)
Container::iterator get(Container &c, Position position)
void run(Expr &expr, Dev &dev)
const Product< Lhs, Rhs > prod(const Lhs &lhs, const Rhs &rhs)