10 #ifndef EIGEN_EMULATE_CXX11_META_H
11 #define EIGEN_EMULATE_CXX11_META_H
19 template <
typename T,
size_t n>
class array {
22 EIGEN_STRONG_INLINE T& operator[] (
size_t index) {
return values[index]; }
24 EIGEN_STRONG_INLINE
const T& operator[] (
size_t index)
const {
return values[index]; }
26 static const std::size_t size() {
return n; }
31 EIGEN_STRONG_INLINE array() { }
32 explicit EIGEN_DEVICE_FUNC
33 EIGEN_STRONG_INLINE array(
const T& v) {
34 EIGEN_STATIC_ASSERT(n==1, YOU_MADE_A_PROGRAMMING_MISTAKE)
38 EIGEN_STRONG_INLINE array(const T& v1, const T& v2) {
39 EIGEN_STATIC_ASSERT(n==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
44 EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3) {
45 EIGEN_STATIC_ASSERT(n==3, YOU_MADE_A_PROGRAMMING_MISTAKE)
51 EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3,
53 EIGEN_STATIC_ASSERT(n==4, YOU_MADE_A_PROGRAMMING_MISTAKE)
60 EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4,
62 EIGEN_STATIC_ASSERT(n==5, YOU_MADE_A_PROGRAMMING_MISTAKE)
70 EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4,
71 const T& v5, const T& v6) {
72 EIGEN_STATIC_ASSERT(n==6, YOU_MADE_A_PROGRAMMING_MISTAKE)
81 EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4,
82 const T& v5, const T& v6, const T& v7) {
83 EIGEN_STATIC_ASSERT(n==7, YOU_MADE_A_PROGRAMMING_MISTAKE)
93 EIGEN_STRONG_INLINE array(
94 const T& v1, const T& v2, const T& v3, const T& v4,
95 const T& v5, const T& v6, const T& v7, const T& v8) {
96 EIGEN_STATIC_ASSERT(n==8, YOU_MADE_A_PROGRAMMING_MISTAKE)
107 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES
108 array(std::initializer_list<T> l) {
109 eigen_assert(l.size() == n);
110 internal::smart_copy(l.begin(), l.end(), values);
124 struct empty_list {
static const std::size_t count = 0; };
126 template<
typename T,
typename Tail=empty_list>
struct type_list {
128 typedef Tail TailType;
130 static const Tail tail;
131 static const std::size_t count = 1 + Tail::count;
134 struct null_type { };
136 template<
typename T1 = null_type,
typename T2 = null_type,
typename T3 = null_type,
137 typename T4 = null_type,
typename T5 = null_type,
typename T6 = null_type,
138 typename T7 = null_type,
typename T8 = null_type>
139 struct make_type_list {
140 typedef typename make_type_list<T2, T3, T4, T5, T6, T7, T8>::type tailresult;
142 typedef type_list<T1, tailresult> type;
145 template<>
struct make_type_list<> {
146 typedef empty_list type;
150 template <std::
size_t index,
class TList>
struct get_type;
152 template <
class Head,
class Tail>
153 struct get_type<0, type_list<Head, Tail> >
158 template <std::
size_t i,
class Head,
class Tail>
159 struct get_type<i, type_list<Head, Tail> >
161 typedef typename get_type<i-1, Tail>::type type;
166 template <
typename T, T n>
169 static const T value = n;
173 template<
typename T,
size_t n, T V>
struct gen_numeric_list_repeated;
175 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 1, V> {
176 typedef typename make_type_list<type2val<T, V> >::type type;
179 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 2, V> {
180 typedef typename make_type_list<type2val<T, V>, type2val<T, V> >::type type;
183 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 3, V> {
184 typedef typename make_type_list<type2val<T, V>, type2val<T, V>, type2val<T, V> >::type type;
187 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 4, V> {
188 typedef typename make_type_list<type2val<T, V>, type2val<T, V>, type2val<T, V>, type2val<T, V> >::type type;
191 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 5, V> {
192 typedef typename make_type_list<type2val<T, V>, type2val<T, V>, type2val<T, V>, type2val<T, V>, type2val<T, V> >::type type;
195 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 6, V> {
196 typedef typename make_type_list<type2val<T, V>, type2val<T, V>, type2val<T, V>,
197 type2val<T, V>, type2val<T, V>, type2val<T, V> >::type type;
200 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 7, V> {
201 typedef typename make_type_list<type2val<T, V>, type2val<T, V>, type2val<T, V>,
202 type2val<T, V>, type2val<T, V>, type2val<T, V>,
203 type2val<T, V> >::type type;
206 template<
typename T, T V>
struct gen_numeric_list_repeated<T, 8, V> {
207 typedef typename make_type_list<type2val<T, V>, type2val<T, V>, type2val<T, V>,
208 type2val<T, V>, type2val<T, V>, type2val<T, V>,
209 type2val<T, V>, type2val<T, V> >::type type;
213 template <std::
size_t index,
class NList>
struct get;
215 template <std::
size_t i>
216 struct get<i, empty_list>
218 get() { eigen_assert(
false &&
"index overflow"); }
220 static const char value =
'\0';
223 template <std::
size_t i,
class Head>
224 struct get<i, type_list<Head, empty_list> >
226 get() { eigen_assert(
false &&
"index overflow"); }
228 static const char value =
'\0';
231 template <
class Head>
232 struct get<0, type_list<Head, empty_list> >
234 typedef typename Head::type type;
235 static const type value = Head::value;
238 template <
class Head,
class Tail>
239 struct get<0, type_list<Head, Tail> >
241 typedef typename Head::type type;
242 static const type value = Head::value;
245 template <std::
size_t i,
class Head,
class Tail>
246 struct get<i, type_list<Head, Tail> >
248 typedef typename Tail::HeadType::type type;
249 static const type value =
get<i-1, Tail>::value;
253 template <
class NList>
struct arg_prod {
254 static const typename NList::HeadType::type value = get<0, NList>::value * arg_prod<typename NList::TailType>::value;
256 template <>
struct arg_prod<empty_list> {
257 static const int value = 1;
261 template<
int n,
typename t>
262 array<t, n> repeat(t v) {
268 template<std::
size_t I,
class Head,
class Tail>
269 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename Head::type array_get(type_list<Head, Tail>&) {
270 return get<I, type_list<Head, Tail> >::value;
272 template<std::
size_t I,
class Head,
class Tail>
273 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename Head::type array_get(
const type_list<Head, Tail>&) {
274 return get<I, type_list<Head, Tail> >::value;
277 template <
class NList>
278 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename NList::HeadType::type array_prod(
const NList&) {
279 return arg_prod<NList>::value;
282 template<std::
size_t n,
typename t>
283 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(
const array<t, n>& a) {
285 for (
size_t i = 0; i < n; ++i) { prod *= a[i]; }
289 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(
const array<t, 0>& ) {
294 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(
const std::vector<t>& a) {
295 eigen_assert(a.size() > 0);
297 for (
size_t i = 0; i < a.size(); ++i) { prod *= a[i]; }
301 template<std::
size_t I,
class T, std::
size_t N>
302 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& array_get(array<T,N>& a) {
305 template<std::
size_t I,
class T, std::
size_t N>
306 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& array_get(
const array<T,N>& a) {
310 template<std::
size_t I,
class T>
311 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& array_get(std::vector<T>& a) {
314 template<std::
size_t I,
class T>
315 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& array_get(
const std::vector<T>& a) {
319 template <
typename T>
struct array_size;
320 template<
class T, std::
size_t N>
struct array_size<array<T,N> > {
321 static const size_t value = N;
323 template <
typename T>
struct array_size;
324 template<
class T, std::
size_t N>
struct array_size<array<T,N>& > {
325 static const size_t value = N;
327 template <
typename T>
struct array_size;
328 template<
class T, std::
size_t N>
struct array_size<const array<T,N> > {
329 static const size_t value = N;
331 template <
typename T>
struct array_size;
332 template<
class T, std::
size_t N>
struct array_size<const array<T,N>& > {
333 static const size_t value = N;
337 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a + b; }
340 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a * b; }
343 struct logical_and_op {
344 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a && b; }
346 struct logical_or_op {
347 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a || b; }
351 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a == b; }
353 struct not_equal_op {
354 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a != b; }
357 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a < b; }
359 struct lesser_equal_op {
360 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a <= b; }
364 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a > b; }
366 struct greater_equal_op {
367 template<
typename A,
typename B>
static inline bool run(A a, B b) {
return a >= b; }
371 template<
typename A>
static inline bool run(A a) {
return !a; }
374 template<
typename A>
static inline bool run(A a) {
return -a; }
376 struct greater_equal_zero_op {
377 template<
typename A>
static inline bool run(A a) {
return a >= 0; }
381 template<
typename Reducer,
typename Op,
typename A, std::
size_t N>
382 struct ArrayApplyAndReduce {
383 static inline bool run(
const array<A, N>& a) {
384 EIGEN_STATIC_ASSERT(N >= 2, YOU_MADE_A_PROGRAMMING_MISTAKE);
385 bool result = Reducer::run(Op::run(a[0]), Op::run(a[1]));
386 for (
size_t i = 2; i < N; ++i) {
387 result = Reducer::run(result, Op::run(a[i]));
393 template<
typename Reducer,
typename Op,
typename A>
394 struct ArrayApplyAndReduce<Reducer, Op, A, 1> {
395 static inline bool run(
const array<A, 1>& a) {
396 return Op::run(a[0]);
400 template<
typename Reducer,
typename Op,
typename A, std::
size_t N>
401 inline bool array_apply_and_reduce(
const array<A, N>& a) {
402 return ArrayApplyAndReduce<Reducer, Op, A, N>::run(a);
405 template<
typename Reducer,
typename Op,
typename A,
typename B, std::
size_t N>
406 struct ArrayZipAndReduce {
407 static inline bool run(
const array<A, N>& a,
const array<B, N>& b) {
408 EIGEN_STATIC_ASSERT(N >= 2, YOU_MADE_A_PROGRAMMING_MISTAKE);
409 bool result = Reducer::run(Op::run(a[0], b[0]), Op::run(a[1], b[1]));
410 for (
size_t i = 2; i < N; ++i) {
411 result = Reducer::run(result, Op::run(a[i], b[i]));
417 template<
typename Reducer,
typename Op,
typename A,
typename B>
418 struct ArrayZipAndReduce<Reducer, Op, A, B, 1> {
419 static inline bool run(
const array<A, 1>& a,
const array<B, 1>& b) {
420 return Op::run(a[0], b[0]);
424 template<
typename Reducer,
typename Op,
typename A,
typename B, std::
size_t N>
425 inline bool array_zip_and_reduce(
const array<A, N>& a,
const array<B, N>& b) {
426 return ArrayZipAndReduce<Reducer, Op, A, B, N>::run(a, b);
435 #endif // EIGEN_EMULATE_CXX11_META_H
Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13