10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H 14 #if EIGEN_HAS_CONSTEXPR && EIGEN_HAS_VARIADIC_TEMPLATES 16 #define EIGEN_HAS_INDEX_LIST 40 template <DenseIndex n>
43 EIGEN_DEVICE_FUNC constexpr
operator DenseIndex()
const {
return n; }
51 template <DenseIndex f, DenseIndex s>
52 struct type2indexpair {
56 constexpr EIGEN_DEVICE_FUNC
operator IndexPair<DenseIndex>()
const {
57 return IndexPair<DenseIndex>(
f,
s);
60 EIGEN_DEVICE_FUNC
void set(
const IndexPair<DenseIndex>& val) {
67 template<DenseIndex n>
struct NumTraits<type2index<
n> >
72 RequireInitialization =
false,
78 EIGEN_DEVICE_FUNC
static inline Real
epsilon() {
return 0; }
79 EIGEN_DEVICE_FUNC
static inline Real dummy_precision() {
return 0; }
80 EIGEN_DEVICE_FUNC
static inline Real highest() {
return n; }
81 EIGEN_DEVICE_FUNC
static inline Real lowest() {
return n; }
86 EIGEN_DEVICE_FUNC
void update_value(
T& val,
DenseIndex new_val) {
89 template <DenseIndex n>
90 EIGEN_DEVICE_FUNC
void update_value(type2index<n>& val,
DenseIndex new_val) {
95 EIGEN_DEVICE_FUNC
void update_value(
T& val, IndexPair<DenseIndex> new_val) {
98 template <DenseIndex f, DenseIndex s>
99 EIGEN_DEVICE_FUNC
void update_value(type2indexpair<f, s>& val, IndexPair<DenseIndex> new_val) {
104 template <
typename T>
105 struct is_compile_time_constant {
106 static constexpr
bool value =
false;
109 template <DenseIndex
idx>
110 struct is_compile_time_constant<type2index<idx> > {
111 static constexpr
bool value =
true;
113 template <DenseIndex
idx>
114 struct is_compile_time_constant<const type2index<idx> > {
115 static constexpr
bool value =
true;
117 template <DenseIndex
idx>
118 struct is_compile_time_constant<type2index<idx>& > {
119 static constexpr
bool value =
true;
121 template <DenseIndex
idx>
122 struct is_compile_time_constant<const type2index<idx>& > {
123 static constexpr
bool value =
true;
126 template <DenseIndex f, DenseIndex s>
127 struct is_compile_time_constant<type2indexpair<
f,
s> > {
128 static constexpr
bool value =
true;
130 template <DenseIndex f, DenseIndex s>
131 struct is_compile_time_constant<const type2indexpair<
f,
s> > {
132 static constexpr
bool value =
true;
134 template <DenseIndex f, DenseIndex s>
135 struct is_compile_time_constant<type2indexpair<
f,
s>& > {
136 static constexpr
bool value =
true;
138 template <DenseIndex f, DenseIndex s>
139 struct is_compile_time_constant<const type2indexpair<
f,
s>& > {
140 static constexpr
bool value =
true;
144 template<
typename...
T>
147 template<
typename T,
typename...
O>
148 struct IndexTuple<T,
O...> {
149 EIGEN_DEVICE_FUNC constexpr IndexTuple() :
head(), others() { }
150 EIGEN_DEVICE_FUNC constexpr IndexTuple(
const T&
v,
const O... o) :
head(v), others(o...) { }
152 constexpr
static int count = 1 +
sizeof...(O);
154 IndexTuple<
O...> others;
156 typedef IndexTuple<
O...> Other;
160 struct IndexTuple<T> {
161 EIGEN_DEVICE_FUNC constexpr IndexTuple() :
head() { }
162 EIGEN_DEVICE_FUNC constexpr IndexTuple(
const T&
v) :
head(v) { }
164 constexpr
static int count = 1;
170 template<
int N,
typename... T>
171 struct IndexTupleExtractor;
173 template<
int N,
typename T,
typename...
O>
174 struct IndexTupleExtractor<N, T,
O...> {
176 typedef typename IndexTupleExtractor<N-1,
O...>::ValType ValType;
178 EIGEN_DEVICE_FUNC
static constexpr ValType& get_val(IndexTuple<T, O...>& val) {
179 return IndexTupleExtractor<N-1, O...>::get_val(val.others);
182 EIGEN_DEVICE_FUNC
static constexpr
const ValType& get_val(
const IndexTuple<T, O...>& val) {
183 return IndexTupleExtractor<N-1, O...>::get_val(val.others);
185 template <
typename V>
186 EIGEN_DEVICE_FUNC
static void set_val(IndexTuple<T, O...>& val,
V& new_val) {
187 IndexTupleExtractor<N-1, O...>::set_val(val.others, new_val);
192 template<
typename T,
typename...
O>
193 struct IndexTupleExtractor<0, T,
O...> {
197 EIGEN_DEVICE_FUNC
static constexpr ValType& get_val(IndexTuple<T, O...>& val) {
200 EIGEN_DEVICE_FUNC
static constexpr
const ValType& get_val(
const IndexTuple<T, O...>& val) {
203 template <
typename V>
204 EIGEN_DEVICE_FUNC
static void set_val(IndexTuple<T, O...>& val,
V& new_val) {
211 template <
int N,
typename T,
typename...
O>
212 EIGEN_DEVICE_FUNC constexpr
typename IndexTupleExtractor<
N,
T,
O...>::ValType&
array_get(IndexTuple<T, O...>&
tuple) {
213 return IndexTupleExtractor<N, T, O...>::get_val(tuple);
215 template <
int N,
typename T,
typename...
O>
216 EIGEN_DEVICE_FUNC constexpr
const typename IndexTupleExtractor<
N,
T,
O...>::ValType&
array_get(
const IndexTuple<T, O...>&
tuple) {
217 return IndexTupleExtractor<N, T, O...>::get_val(tuple);
219 template <
typename T,
typename...
O>
220 struct array_size<IndexTuple<T,
O...> > {
221 static const size_t value = IndexTuple<
T,
O...>::count;
223 template <
typename T,
typename...
O>
224 struct array_size<const IndexTuple<T,
O...> > {
225 static const size_t value = IndexTuple<
T,
O...>::count;
231 template <DenseIndex Idx,
typename ValueT>
233 template <
typename... T>
234 EIGEN_DEVICE_FUNC
static constexpr ValueT
get(
const DenseIndex i,
const IndexTuple<T...>&
t) {
238 template <
typename... T>
239 EIGEN_DEVICE_FUNC
static void set(
const DenseIndex i, IndexTuple<T...>&
t,
const ValueT&
value) {
241 update_value(array_get<Idx>(
t),
value);
247 template <
typename... T>
248 EIGEN_DEVICE_FUNC
static constexpr
bool value_known_statically(
const DenseIndex i,
const IndexTuple<T...>&
t) {
249 return ((i == Idx) & is_compile_time_constant<
typename IndexTupleExtractor<Idx, T...>::ValType>::
value) ||
250 tuple_coeff<Idx-1, ValueT>::value_known_statically(i, t);
253 template <
typename... T>
254 EIGEN_DEVICE_FUNC
static constexpr
bool values_up_to_known_statically(
const IndexTuple<T...>& t) {
255 return is_compile_time_constant<
typename IndexTupleExtractor<Idx, T...>::ValType>
::value &&
256 tuple_coeff<Idx-1, ValueT>::values_up_to_known_statically(t);
259 template <
typename... T>
260 EIGEN_DEVICE_FUNC
static constexpr
bool values_up_to_statically_known_to_increase(
const IndexTuple<T...>& t) {
261 return is_compile_time_constant<
typename IndexTupleExtractor<Idx, T...>::ValType>
::value &&
262 is_compile_time_constant<
typename IndexTupleExtractor<Idx, T...>::ValType>
::value &&
263 array_get<Idx>(
t) > array_get<Idx-1>(t) &&
264 tuple_coeff<Idx-1, ValueT>::values_up_to_statically_known_to_increase(t);
268 template <
typename ValueT>
269 struct tuple_coeff<0, ValueT> {
270 template <
typename... T>
271 EIGEN_DEVICE_FUNC
static constexpr ValueT
get(
const DenseIndex ,
const IndexTuple<T...>&
t) {
273 return array_get<0>(
t);
275 template <
typename... T>
276 EIGEN_DEVICE_FUNC
static void set(
const DenseIndex
i, IndexTuple<T...>&
t,
const ValueT
value) {
278 update_value(array_get<0>(t),
value);
280 template <
typename... T>
281 EIGEN_DEVICE_FUNC
static constexpr
bool value_known_statically(
const DenseIndex i,
const IndexTuple<T...>&) {
282 return is_compile_time_constant<
typename IndexTupleExtractor<0, T...>::ValType>
::value & (i == 0);
285 template <
typename... T>
286 EIGEN_DEVICE_FUNC
static constexpr
bool values_up_to_known_statically(
const IndexTuple<T...>&) {
287 return is_compile_time_constant<
typename IndexTupleExtractor<0, T...>::ValType>
::value;
290 template <
typename... T>
291 EIGEN_DEVICE_FUNC
static constexpr
bool values_up_to_statically_known_to_increase(
const IndexTuple<T...>&) {
299 template<
typename FirstType,
typename... OtherTypes>
300 struct IndexList : internal::IndexTuple<FirstType, OtherTypes...> {
302 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1,
DenseIndex>
::get(i, *
this);
305 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1,
DenseIndex>
::get(i, *
this);
308 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1,
DenseIndex>
::set(i, *
this,
value);
311 EIGEN_DEVICE_FUNC constexpr IndexList(
const internal::IndexTuple<FirstType, OtherTypes...>& other) :
internal::IndexTuple<FirstType, OtherTypes...>(other) { }
312 EIGEN_DEVICE_FUNC constexpr IndexList(FirstType&
first, OtherTypes... other) :
internal::IndexTuple<FirstType, OtherTypes...>(first, other...) { }
313 EIGEN_DEVICE_FUNC constexpr IndexList() :
internal::IndexTuple<FirstType, OtherTypes...>() { }
315 EIGEN_DEVICE_FUNC constexpr
bool value_known_statically(
const DenseIndex i)
const {
316 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1,
DenseIndex>::value_known_statically(i, *
this);
318 EIGEN_DEVICE_FUNC constexpr
bool all_values_known_statically()
const {
319 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1,
DenseIndex>::values_up_to_known_statically(*
this);
322 EIGEN_DEVICE_FUNC constexpr
bool values_statically_known_to_increase()
const {
323 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1,
DenseIndex>::values_up_to_statically_known_to_increase(*
this);
328 template<
typename FirstType,
typename... OtherTypes>
329 constexpr IndexList<FirstType, OtherTypes...> make_index_list(FirstType val1, OtherTypes... other_vals) {
330 return IndexList<FirstType, OtherTypes...>(val1, other_vals...);
334 template<
typename FirstType,
typename... OtherTypes>
335 struct IndexPairList : internal::IndexTuple<FirstType, OtherTypes...> {
337 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1, IndexPair<DenseIndex>>
::get(i, *
this);
340 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...>>
::value-1, IndexPair<DenseIndex> >
::set(i, *
this,
value);
343 EIGEN_DEVICE_FUNC constexpr IndexPairList(
const internal::IndexTuple<FirstType, OtherTypes...>& other) :
internal::IndexTuple<FirstType, OtherTypes...>(other) { }
344 EIGEN_DEVICE_FUNC constexpr IndexPairList() :
internal::IndexTuple<FirstType, OtherTypes...>() { }
346 EIGEN_DEVICE_FUNC constexpr
bool value_known_statically(
const DenseIndex i)
const {
347 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >
::value-1,
DenseIndex>::value_known_statically(i, *
this);
353 template<
typename FirstType,
typename... OtherTypes>
size_t array_prod(
const IndexList<FirstType, OtherTypes...>&
sizes) {
355 for (
int i = 0; i < array_size<IndexList<FirstType, OtherTypes...> >
::value; ++
i) {
361 template<
typename FirstType,
typename... OtherTypes>
struct array_size<IndexList<FirstType, OtherTypes...> > {
362 static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >
::value;
364 template<
typename FirstType,
typename... OtherTypes>
struct array_size<const IndexList<FirstType, OtherTypes...> > {
365 static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >
::value;
368 template<
typename FirstType,
typename... OtherTypes>
struct array_size<IndexPairList<FirstType, OtherTypes...> > {
369 static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >
::value;
371 template<
typename FirstType,
typename... OtherTypes>
struct array_size<const IndexPairList<FirstType, OtherTypes...> > {
372 static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >
::value;
375 template<
DenseIndex N,
typename FirstType,
typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr
DenseIndex array_get(IndexList<FirstType, OtherTypes...>&
a) {
376 return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a);
378 template<
DenseIndex N,
typename FirstType,
typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr
DenseIndex array_get(
const IndexList<FirstType, OtherTypes...>&
a) {
379 return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a);
382 template <
typename T>
383 struct index_known_statically_impl {
384 EIGEN_DEVICE_FUNC
static constexpr
bool run(
const DenseIndex) {
389 template <
typename FirstType,
typename... OtherTypes>
390 struct index_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
391 EIGEN_DEVICE_FUNC
static constexpr
bool run(
const DenseIndex i) {
392 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
396 template <
typename FirstType,
typename... OtherTypes>
397 struct index_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
398 EIGEN_DEVICE_FUNC
static constexpr
bool run(
const DenseIndex i) {
399 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
404 template <
typename T>
405 struct all_indices_known_statically_impl {
406 static constexpr
bool run() {
411 template <
typename FirstType,
typename... OtherTypes>
412 struct all_indices_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
413 EIGEN_DEVICE_FUNC
static constexpr
bool run() {
414 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
418 template <
typename FirstType,
typename... OtherTypes>
419 struct all_indices_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
420 EIGEN_DEVICE_FUNC
static constexpr
bool run() {
421 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
426 template <
typename T>
427 struct indices_statically_known_to_increase_impl {
428 EIGEN_DEVICE_FUNC
static constexpr
bool run() {
433 template <
typename FirstType,
typename... OtherTypes>
434 struct indices_statically_known_to_increase_impl<IndexList<FirstType, OtherTypes...> > {
435 EIGEN_DEVICE_FUNC
static constexpr
bool run() {
436 return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
440 template <
typename FirstType,
typename... OtherTypes>
441 struct indices_statically_known_to_increase_impl<const IndexList<FirstType, OtherTypes...> > {
442 EIGEN_DEVICE_FUNC
static constexpr
bool run() {
443 return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
448 template <
typename Tx>
449 struct index_statically_eq_impl {
455 template <
typename FirstType,
typename... OtherTypes>
456 struct index_statically_eq_impl<IndexList<FirstType, OtherTypes...> > {
458 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
459 (IndexList<FirstType, OtherTypes...>().
get(i) ==
value);
463 template <
typename FirstType,
typename... OtherTypes>
464 struct index_statically_eq_impl<const IndexList<FirstType, OtherTypes...> > {
466 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
467 (IndexList<FirstType, OtherTypes...>().
get(i) ==
value);
472 template <
typename T>
473 struct index_statically_ne_impl {
479 template <
typename FirstType,
typename... OtherTypes>
480 struct index_statically_ne_impl<IndexList<FirstType, OtherTypes...> > {
482 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
483 (IndexList<FirstType, OtherTypes...>().
get(i) !=
value);
487 template <
typename FirstType,
typename... OtherTypes>
488 struct index_statically_ne_impl<const IndexList<FirstType, OtherTypes...> > {
490 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
491 (IndexList<FirstType, OtherTypes...>().
get(i) !=
value);
496 template <
typename T>
497 struct index_statically_gt_impl {
503 template <
typename FirstType,
typename... OtherTypes>
504 struct index_statically_gt_impl<IndexList<FirstType, OtherTypes...> > {
506 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
507 (IndexList<FirstType, OtherTypes...>().
get(i) >
value);
511 template <
typename FirstType,
typename... OtherTypes>
512 struct index_statically_gt_impl<const IndexList<FirstType, OtherTypes...> > {
514 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
515 (IndexList<FirstType, OtherTypes...>().
get(i) >
value);
521 template <
typename T>
522 struct index_statically_lt_impl {
528 template <
typename FirstType,
typename... OtherTypes>
529 struct index_statically_lt_impl<IndexList<FirstType, OtherTypes...> > {
531 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
532 (IndexList<FirstType, OtherTypes...>().
get(i) <
value);
536 template <
typename FirstType,
typename... OtherTypes>
537 struct index_statically_lt_impl<const IndexList<FirstType, OtherTypes...> > {
539 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
540 (IndexList<FirstType, OtherTypes...>().
get(i) <
value);
546 template <
typename Tx>
547 struct index_pair_first_statically_eq_impl {
553 template <
typename FirstType,
typename... OtherTypes>
554 struct index_pair_first_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
556 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
557 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).first ==
value);
561 template <
typename FirstType,
typename... OtherTypes>
562 struct index_pair_first_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
564 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
565 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).first ==
value);
571 template <
typename Tx>
572 struct index_pair_second_statically_eq_impl {
578 template <
typename FirstType,
typename... OtherTypes>
579 struct index_pair_second_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
581 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
582 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).second ==
value);
586 template <
typename FirstType,
typename... OtherTypes>
587 struct index_pair_second_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
589 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
590 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).second ==
value);
603 template <
typename T>
610 template <
typename T>
617 template <
typename T>
624 template <
typename T>
631 template <
typename T>
638 template <
typename T>
645 template <
typename T>
652 template <
typename Tx>
659 template <
typename Tx>
676 template <
typename T>
681 template <
typename T>
686 template <
typename T>
691 template <
typename T>
696 template <
typename T>
701 template <
typename T>
706 template <
typename T>
711 template <
typename T>
716 template <
typename T>
725 #endif // EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_first_statically_eq(DenseIndex i, DenseIndex value)
#define EIGEN_ALWAYS_INLINE
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
#define EIGEN_STRONG_INLINE
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_gt(DenseIndex i, DenseIndex value)
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex)
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_known_statically(DenseIndex i)
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_eq(DenseIndex i, DenseIndex value)
std::vector< Array2i > sizes
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_ne(DenseIndex i, DenseIndex value)
Namespace containing all symbols from the Eigen library.
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_lt(DenseIndex i, DenseIndex value)
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_second_statically_eq(DenseIndex i, DenseIndex value)
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex)
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool indices_statically_known_to_increase()
constexpr int first(int i)
Implementation details for constexpr functions.
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex)
Eigen::Triplet< double > T
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool all_indices_known_statically()
void set(Container &c, Position position, const Value &value)
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex)
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
mp::number< mp::cpp_dec_float< 100 >, mp::et_on > Real
EIGEN_DEVICE_FUNC SegmentReturnType head(Index n)
This is the const version of head(Index).
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex)
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex)
const Index array_get(DimensionList< Index, Rank > &)
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run()
Container::iterator get(Container &c, Position position)
void run(Expr &expr, Dev &dev)
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex)