Loading...
Searching...
No Matches
TensorIndexList.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
11#define EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
12
13
14#if EIGEN_HAS_CONSTEXPR && EIGEN_HAS_VARIADIC_TEMPLATES
15
16#define EIGEN_HAS_INDEX_LIST
17
18namespace Eigen {
19
20template <DenseIndex n>
21struct type2index {
22 static const DenseIndex value = n;
23 EIGEN_DEVICE_FUNC constexpr operator DenseIndex() const { return n; }
24 EIGEN_DEVICE_FUNC void set(DenseIndex val) {
25 EIGEN_ONLY_USED_FOR_DEBUG(val);
26 eigen_assert(val == n);
27 }
28};
29
30// This can be used with IndexPairList to get compile-time constant pairs,
31// such as IndexPairList<type2indexpair<1,2>, type2indexpair<3,4>>().
32template <DenseIndex f, DenseIndex s>
33struct type2indexpair {
34 static const DenseIndex first = f;
35 static const DenseIndex second = s;
36
37 constexpr EIGEN_DEVICE_FUNC operator IndexPair<DenseIndex>() const {
38 return IndexPair<DenseIndex>(f, s);
39 }
40
41 EIGEN_DEVICE_FUNC void set(const IndexPair<DenseIndex>& val) {
42 EIGEN_ONLY_USED_FOR_DEBUG(val);
43 eigen_assert(val.first == f);
44 eigen_assert(val.second == s);
45 }
46};
47
48
49template<DenseIndex n> struct NumTraits<type2index<n> >
50{
51 typedef DenseIndex Real;
52 enum {
53 IsComplex = 0,
54 RequireInitialization = false,
55 ReadCost = 1,
56 AddCost = 1,
57 MulCost = 1
58 };
59
60 EIGEN_DEVICE_FUNC static inline Real epsilon() { return 0; }
61 EIGEN_DEVICE_FUNC static inline Real dummy_precision() { return 0; }
62 EIGEN_DEVICE_FUNC static inline Real highest() { return n; }
63 EIGEN_DEVICE_FUNC static inline Real lowest() { return n; }
64};
65
66namespace internal {
67template <typename T>
68EIGEN_DEVICE_FUNC void update_value(T& val, DenseIndex new_val) {
69 val = new_val;
70}
71template <DenseIndex n>
72EIGEN_DEVICE_FUNC void update_value(type2index<n>& val, DenseIndex new_val) {
73 val.set(new_val);
74}
75
76template <typename T>
77EIGEN_DEVICE_FUNC void update_value(T& val, IndexPair<DenseIndex> new_val) {
78 val = new_val;
79}
80template <DenseIndex f, DenseIndex s>
81EIGEN_DEVICE_FUNC void update_value(type2indexpair<f, s>& val, IndexPair<DenseIndex> new_val) {
82 val.set(new_val);
83}
84
85
86template <typename T>
87struct is_compile_time_constant {
88 static constexpr bool value = false;
89};
90
91template <DenseIndex idx>
92struct is_compile_time_constant<type2index<idx> > {
93 static constexpr bool value = true;
94};
95template <DenseIndex idx>
96struct is_compile_time_constant<const type2index<idx> > {
97 static constexpr bool value = true;
98};
99template <DenseIndex idx>
100struct is_compile_time_constant<type2index<idx>& > {
101 static constexpr bool value = true;
102};
103template <DenseIndex idx>
104struct is_compile_time_constant<const type2index<idx>& > {
105 static constexpr bool value = true;
106};
107
108template <DenseIndex f, DenseIndex s>
109struct is_compile_time_constant<type2indexpair<f, s> > {
110 static constexpr bool value = true;
111};
112template <DenseIndex f, DenseIndex s>
113struct is_compile_time_constant<const type2indexpair<f, s> > {
114 static constexpr bool value = true;
115};
116template <DenseIndex f, DenseIndex s>
117struct is_compile_time_constant<type2indexpair<f, s>& > {
118 static constexpr bool value = true;
119};
120template <DenseIndex f, DenseIndex s>
121struct is_compile_time_constant<const type2indexpair<f, s>& > {
122 static constexpr bool value = true;
123};
124
125
126template<typename... T>
127struct IndexTuple;
128
129template<typename T, typename... O>
130struct IndexTuple<T, O...> {
131 EIGEN_DEVICE_FUNC constexpr IndexTuple() : head(), others() { }
132 EIGEN_DEVICE_FUNC constexpr IndexTuple(const T& v, const O... o) : head(v), others(o...) { }
133
134 constexpr static int count = 1 + sizeof...(O);
135 T head;
136 IndexTuple<O...> others;
137 typedef T Head;
138 typedef IndexTuple<O...> Other;
139};
140
141template<typename T>
142 struct IndexTuple<T> {
143 EIGEN_DEVICE_FUNC constexpr IndexTuple() : head() { }
144 EIGEN_DEVICE_FUNC constexpr IndexTuple(const T& v) : head(v) { }
145
146 constexpr static int count = 1;
147 T head;
148 typedef T Head;
149};
150
151
152template<int N, typename... T>
153struct IndexTupleExtractor;
154
155template<int N, typename T, typename... O>
156struct IndexTupleExtractor<N, T, O...> {
157
158 typedef typename IndexTupleExtractor<N-1, O...>::ValType ValType;
159
160 EIGEN_DEVICE_FUNC static constexpr ValType& get_val(IndexTuple<T, O...>& val) {
161 return IndexTupleExtractor<N-1, O...>::get_val(val.others);
162 }
163
164 EIGEN_DEVICE_FUNC static constexpr const ValType& get_val(const IndexTuple<T, O...>& val) {
165 return IndexTupleExtractor<N-1, O...>::get_val(val.others);
166 }
167 template <typename V>
168 EIGEN_DEVICE_FUNC static void set_val(IndexTuple<T, O...>& val, V& new_val) {
169 IndexTupleExtractor<N-1, O...>::set_val(val.others, new_val);
170 }
171
172};
173
174template<typename T, typename... O>
175 struct IndexTupleExtractor<0, T, O...> {
176
177 typedef T ValType;
178
179 EIGEN_DEVICE_FUNC static constexpr ValType& get_val(IndexTuple<T, O...>& val) {
180 return val.head;
181 }
182 EIGEN_DEVICE_FUNC static constexpr const ValType& get_val(const IndexTuple<T, O...>& val) {
183 return val.head;
184 }
185 template <typename V>
186 EIGEN_DEVICE_FUNC static void set_val(IndexTuple<T, O...>& val, V& new_val) {
187 val.head = new_val;
188 }
189};
190
191
192
193template <int N, typename T, typename... O>
194EIGEN_DEVICE_FUNC constexpr typename IndexTupleExtractor<N, T, O...>::ValType& array_get(IndexTuple<T, O...>& tuple) {
195 return IndexTupleExtractor<N, T, O...>::get_val(tuple);
196}
197template <int N, typename T, typename... O>
198EIGEN_DEVICE_FUNC constexpr const typename IndexTupleExtractor<N, T, O...>::ValType& array_get(const IndexTuple<T, O...>& tuple) {
199 return IndexTupleExtractor<N, T, O...>::get_val(tuple);
200}
201template <typename T, typename... O>
202 struct array_size<IndexTuple<T, O...> > {
203 static const size_t value = IndexTuple<T, O...>::count;
204};
205template <typename T, typename... O>
206 struct array_size<const IndexTuple<T, O...> > {
207 static const size_t value = IndexTuple<T, O...>::count;
208};
209
210
211
212
213template <DenseIndex Idx, typename ValueT>
214struct tuple_coeff {
215 template <typename... T>
216 EIGEN_DEVICE_FUNC static constexpr ValueT get(const DenseIndex i, const IndexTuple<T...>& t) {
217 // return array_get<Idx>(t) * (i == Idx) + tuple_coeff<Idx-1>::get(i, t) * (i != Idx);
218 return (i == Idx ? array_get<Idx>(t) : tuple_coeff<Idx-1, ValueT>::get(i, t));
219 }
220 template <typename... T>
221 EIGEN_DEVICE_FUNC static void set(const DenseIndex i, IndexTuple<T...>& t, const ValueT& value) {
222 if (i == Idx) {
223 update_value(array_get<Idx>(t), value);
224 } else {
225 tuple_coeff<Idx-1, ValueT>::set(i, t, value);
226 }
227 }
228
229 template <typename... T>
230 EIGEN_DEVICE_FUNC static constexpr bool value_known_statically(const DenseIndex i, const IndexTuple<T...>& t) {
231 return ((i == Idx) & is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value) ||
232 tuple_coeff<Idx-1, ValueT>::value_known_statically(i, t);
233 }
234
235 template <typename... T>
236 EIGEN_DEVICE_FUNC static constexpr bool values_up_to_known_statically(const IndexTuple<T...>& t) {
237 return is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value &&
238 tuple_coeff<Idx-1, ValueT>::values_up_to_known_statically(t);
239 }
240
241 template <typename... T>
242 EIGEN_DEVICE_FUNC static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple<T...>& t) {
243 return is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value &&
244 is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value &&
245 array_get<Idx>(t) > array_get<Idx-1>(t) &&
246 tuple_coeff<Idx-1, ValueT>::values_up_to_statically_known_to_increase(t);
247 }
248};
249
250template <typename ValueT>
251struct tuple_coeff<0, ValueT> {
252 template <typename... T>
253 EIGEN_DEVICE_FUNC static constexpr ValueT get(const DenseIndex /*i*/, const IndexTuple<T...>& t) {
254 // eigen_assert (i == 0); // gcc fails to compile assertions in constexpr
255 return array_get<0>(t)/* * (i == 0)*/;
256 }
257 template <typename... T>
258 EIGEN_DEVICE_FUNC static void set(const DenseIndex i, IndexTuple<T...>& t, const ValueT value) {
259 EIGEN_ONLY_USED_FOR_DEBUG(i);
260 eigen_assert (i == 0);
261 update_value(array_get<0>(t), value);
262 }
263 template <typename... T>
264 EIGEN_DEVICE_FUNC static constexpr bool value_known_statically(const DenseIndex i, const IndexTuple<T...>&) {
265 return is_compile_time_constant<typename IndexTupleExtractor<0, T...>::ValType>::value & (i == 0);
266 }
267
268 template <typename... T>
269 EIGEN_DEVICE_FUNC static constexpr bool values_up_to_known_statically(const IndexTuple<T...>&) {
270 return is_compile_time_constant<typename IndexTupleExtractor<0, T...>::ValType>::value;
271 }
272
273 template <typename... T>
274 EIGEN_DEVICE_FUNC static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple<T...>&) {
275 return true;
276 }
277};
278} // namespace internal
279
298
317template <typename FirstType, typename... OtherTypes>
318struct IndexList : internal::IndexTuple<FirstType, OtherTypes...> {
319 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr DenseIndex operator[] (const DenseIndex i) const {
320 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::get(i, *this);
321 }
322 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr DenseIndex get(const DenseIndex i) const {
323 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::get(i, *this);
324 }
325 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void set(const DenseIndex i, const DenseIndex value) {
326 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::set(i, *this, value);
327 }
328
329 EIGEN_DEVICE_FUNC constexpr IndexList(const internal::IndexTuple<FirstType, OtherTypes...>& other) : internal::IndexTuple<FirstType, OtherTypes...>(other) { }
330 EIGEN_DEVICE_FUNC constexpr IndexList(FirstType& first, OtherTypes... other) : internal::IndexTuple<FirstType, OtherTypes...>(first, other...) { }
331 EIGEN_DEVICE_FUNC constexpr IndexList() : internal::IndexTuple<FirstType, OtherTypes...>() { }
332
333 EIGEN_DEVICE_FUNC constexpr bool value_known_statically(const DenseIndex i) const {
334 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::value_known_statically(i, *this);
335 }
336 EIGEN_DEVICE_FUNC constexpr bool all_values_known_statically() const {
337 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::values_up_to_known_statically(*this);
338 }
339
340 EIGEN_DEVICE_FUNC constexpr bool values_statically_known_to_increase() const {
341 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::values_up_to_statically_known_to_increase(*this);
342 }
343};
344
345
346template<typename FirstType, typename... OtherTypes>
347constexpr IndexList<FirstType, OtherTypes...> make_index_list(FirstType val1, OtherTypes... other_vals) {
348 return IndexList<FirstType, OtherTypes...>(val1, other_vals...);
349}
350
351
352template<typename FirstType, typename... OtherTypes>
353struct IndexPairList : internal::IndexTuple<FirstType, OtherTypes...> {
354 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr IndexPair<DenseIndex> operator[] (const DenseIndex i) const {
355 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, IndexPair<DenseIndex>>::get(i, *this);
356 }
357 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void set(const DenseIndex i, const IndexPair<DenseIndex> value) {
358 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...>>::value-1, IndexPair<DenseIndex> >::set(i, *this, value);
359 }
360
361 EIGEN_DEVICE_FUNC constexpr IndexPairList(const internal::IndexTuple<FirstType, OtherTypes...>& other) : internal::IndexTuple<FirstType, OtherTypes...>(other) { }
362 EIGEN_DEVICE_FUNC constexpr IndexPairList() : internal::IndexTuple<FirstType, OtherTypes...>() { }
363
364 EIGEN_DEVICE_FUNC constexpr bool value_known_statically(const DenseIndex i) const {
365 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::value_known_statically(i, *this);
366 }
367};
368
369namespace internal {
370
371template<typename FirstType, typename... OtherTypes> size_t array_prod(const IndexList<FirstType, OtherTypes...>& sizes) {
372 size_t result = 1;
373 for (int i = 0; i < array_size<IndexList<FirstType, OtherTypes...> >::value; ++i) {
374 result *= sizes[i];
375 }
376 return result;
377}
378
379template<typename FirstType, typename... OtherTypes> struct array_size<IndexList<FirstType, OtherTypes...> > {
380 static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value;
381};
382template<typename FirstType, typename... OtherTypes> struct array_size<const IndexList<FirstType, OtherTypes...> > {
383 static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value;
384};
385
386template<typename FirstType, typename... OtherTypes> struct array_size<IndexPairList<FirstType, OtherTypes...> > {
387 static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value;
388};
389template<typename FirstType, typename... OtherTypes> struct array_size<const IndexPairList<FirstType, OtherTypes...> > {
390 static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value;
391};
392
393template<DenseIndex N, typename FirstType, typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr DenseIndex array_get(IndexList<FirstType, OtherTypes...>& a) {
394 return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a);
395}
396template<DenseIndex N, typename FirstType, typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr DenseIndex array_get(const IndexList<FirstType, OtherTypes...>& a) {
397 return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a);
398}
399
400template <typename T>
401struct index_known_statically_impl {
402 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex) {
403 return false;
404 }
405};
406
407template <typename FirstType, typename... OtherTypes>
408struct index_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
409 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i) {
410 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
411 }
412};
413
414template <typename FirstType, typename... OtherTypes>
415struct index_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
416 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i) {
417 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
418 }
419};
420
421
422template <typename T>
423struct all_indices_known_statically_impl {
424 static constexpr bool run() {
425 return false;
426 }
427};
428
429template <typename FirstType, typename... OtherTypes>
430struct all_indices_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
431 EIGEN_DEVICE_FUNC static constexpr bool run() {
432 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
433 }
434};
435
436template <typename FirstType, typename... OtherTypes>
437struct all_indices_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
438 EIGEN_DEVICE_FUNC static constexpr bool run() {
439 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
440 }
441};
442
443
444template <typename T>
445struct indices_statically_known_to_increase_impl {
446 EIGEN_DEVICE_FUNC static constexpr bool run() {
447 return false;
448 }
449};
450
451template <typename FirstType, typename... OtherTypes>
452 struct indices_statically_known_to_increase_impl<IndexList<FirstType, OtherTypes...> > {
453 EIGEN_DEVICE_FUNC static constexpr bool run() {
454 return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
455 }
456};
457
458template <typename FirstType, typename... OtherTypes>
459 struct indices_statically_known_to_increase_impl<const IndexList<FirstType, OtherTypes...> > {
460 EIGEN_DEVICE_FUNC static constexpr bool run() {
461 return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
462 }
463};
464
465
466template <typename Tx>
467struct index_statically_eq_impl {
468 EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
469 return false;
470 }
471};
472
473template <typename FirstType, typename... OtherTypes>
474struct index_statically_eq_impl<IndexList<FirstType, OtherTypes...> > {
475 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
476 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
477 (IndexList<FirstType, OtherTypes...>().get(i) == value);
478 }
479};
480
481template <typename FirstType, typename... OtherTypes>
482struct index_statically_eq_impl<const IndexList<FirstType, OtherTypes...> > {
483 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
484 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
485 (IndexList<FirstType, OtherTypes...>().get(i) == value);
486 }
487};
488
489
490template <typename T>
491struct index_statically_ne_impl {
492 EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
493 return false;
494 }
495};
496
497template <typename FirstType, typename... OtherTypes>
498struct index_statically_ne_impl<IndexList<FirstType, OtherTypes...> > {
499 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
500 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
501 (IndexList<FirstType, OtherTypes...>().get(i) != value);
502 }
503};
504
505template <typename FirstType, typename... OtherTypes>
506struct index_statically_ne_impl<const IndexList<FirstType, OtherTypes...> > {
507 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
508 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
509 (IndexList<FirstType, OtherTypes...>().get(i) != value);
510 }
511};
512
513
514template <typename T>
515struct index_statically_gt_impl {
516 EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
517 return false;
518 }
519};
520
521template <typename FirstType, typename... OtherTypes>
522struct index_statically_gt_impl<IndexList<FirstType, OtherTypes...> > {
523 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
524 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
525 (IndexList<FirstType, OtherTypes...>().get(i) > value);
526 }
527};
528
529template <typename FirstType, typename... OtherTypes>
530struct index_statically_gt_impl<const IndexList<FirstType, OtherTypes...> > {
531 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
532 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
533 (IndexList<FirstType, OtherTypes...>().get(i) > value);
534 }
535};
536
537
538
539template <typename T>
540struct index_statically_lt_impl {
541 EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
542 return false;
543 }
544};
545
546template <typename FirstType, typename... OtherTypes>
547struct index_statically_lt_impl<IndexList<FirstType, OtherTypes...> > {
548 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
549 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
550 (IndexList<FirstType, OtherTypes...>().get(i) < value);
551 }
552};
553
554template <typename FirstType, typename... OtherTypes>
555struct index_statically_lt_impl<const IndexList<FirstType, OtherTypes...> > {
556 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
557 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
558 (IndexList<FirstType, OtherTypes...>().get(i) < value);
559 }
560};
561
562
563
564template <typename Tx>
565struct index_pair_first_statically_eq_impl {
566 EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
567 return false;
568 }
569};
570
571template <typename FirstType, typename... OtherTypes>
572struct index_pair_first_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
573 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
574 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
575 (IndexPairList<FirstType, OtherTypes...>().operator[](i).first == value);
576 }
577};
578
579template <typename FirstType, typename... OtherTypes>
580struct index_pair_first_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
581 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
582 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
583 (IndexPairList<FirstType, OtherTypes...>().operator[](i).first == value);
584 }
585};
586
587
588
589template <typename Tx>
590struct index_pair_second_statically_eq_impl {
591 EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
592 return false;
593 }
594};
595
596template <typename FirstType, typename... OtherTypes>
597struct index_pair_second_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
598 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
599 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
600 (IndexPairList<FirstType, OtherTypes...>().operator[](i).second == value);
601 }
602};
603
604template <typename FirstType, typename... OtherTypes>
605struct index_pair_second_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
606 EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
607 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
608 (IndexPairList<FirstType, OtherTypes...>().operator[](i).second == value);
609 }
610};
611
612
613} // end namespace internal
614} // end namespace Eigen
615
616#else
617
618namespace Eigen {
619namespace internal {
620
621template <typename T>
622struct index_known_statically_impl {
623 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex) {
624 return false;
625 }
626};
627
628template <typename T>
629struct all_indices_known_statically_impl {
630 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() {
631 return false;
632 }
633};
634
635template <typename T>
636struct indices_statically_known_to_increase_impl {
637 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() {
638 return false;
639 }
640};
641
642template <typename T>
643struct index_statically_eq_impl {
644 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
645 return false;
646 }
647};
648
649template <typename T>
650struct index_statically_ne_impl {
651 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
652 return false;
653 }
654};
655
656template <typename T>
657struct index_statically_gt_impl {
658 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
659 return false;
660 }
661};
662
663template <typename T>
664struct index_statically_lt_impl {
665 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
666 return false;
667 }
668};
669
670template <typename Tx>
671struct index_pair_first_statically_eq_impl {
672 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
673 return false;
674 }
675};
676
677template <typename Tx>
678struct index_pair_second_statically_eq_impl {
679 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
680 return false;
681 }
682};
683
684
685
686} // end namespace internal
687} // end namespace Eigen
688
689#endif
690
691
692namespace Eigen {
693namespace internal {
694template <typename T>
695static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_known_statically(DenseIndex i) {
696 return index_known_statically_impl<T>::run(i);
697}
698
699template <typename T>
700static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool all_indices_known_statically() {
701 return all_indices_known_statically_impl<T>::run();
702}
703
704template <typename T>
705static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool indices_statically_known_to_increase() {
706 return indices_statically_known_to_increase_impl<T>::run();
707}
708
709template <typename T>
710static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_eq(DenseIndex i, DenseIndex value) {
711 return index_statically_eq_impl<T>::run(i, value);
712}
713
714template <typename T>
715static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_ne(DenseIndex i, DenseIndex value) {
716 return index_statically_ne_impl<T>::run(i, value);
717}
718
719template <typename T>
720static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_gt(DenseIndex i, DenseIndex value) {
721 return index_statically_gt_impl<T>::run(i, value);
722}
723
724template <typename T>
725static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_lt(DenseIndex i, DenseIndex value) {
726 return index_statically_lt_impl<T>::run(i, value);
727}
728
729template <typename T>
730static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_first_statically_eq(DenseIndex i, DenseIndex value) {
731 return index_pair_first_statically_eq_impl<T>::run(i, value);
732}
733
734template <typename T>
735static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_second_statically_eq(DenseIndex i, DenseIndex value) {
736 return index_pair_second_statically_eq_impl<T>::run(i, value);
737}
738
739} // end namespace internal
740} // end namespace Eigen
741
742
743#endif // EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
Namespace containing all symbols from the Eigen library.