TensorIndexList.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
00011 #define EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
00012 
00013 
00014 #if EIGEN_HAS_CONSTEXPR && EIGEN_HAS_VARIADIC_TEMPLATES
00015 
00016 #define EIGEN_HAS_INDEX_LIST
00017 
00018 namespace Eigen {
00019 
00040 template <DenseIndex n>
00041 struct type2index {
00042   static const DenseIndex value = n;
00043   EIGEN_DEVICE_FUNC constexpr operator DenseIndex() const { return n; }
00044   EIGEN_DEVICE_FUNC void set(DenseIndex val) {
00045     eigen_assert(val == n);
00046   }
00047 };
00048 
00049 // This can be used with IndexPairList to get compile-time constant pairs,
00050 // such as IndexPairList<type2indexpair<1,2>, type2indexpair<3,4>>().
00051 template <DenseIndex f, DenseIndex s>
00052 struct type2indexpair {
00053   static const DenseIndex first = f;
00054   static const DenseIndex second = s;
00055 
00056   constexpr EIGEN_DEVICE_FUNC operator IndexPair<DenseIndex>() const {
00057     return IndexPair<DenseIndex>(f, s);
00058   }
00059 
00060   EIGEN_DEVICE_FUNC void set(const IndexPair<DenseIndex>& val) {
00061     eigen_assert(val.first == f);
00062     eigen_assert(val.second == s);
00063   }
00064 };
00065 
00066 
00067 template<DenseIndex n> struct NumTraits<type2index<n> >
00068 {
00069   typedef DenseIndex Real;
00070   enum {
00071     IsComplex = 0,
00072     RequireInitialization = false,
00073     ReadCost = 1,
00074     AddCost = 1,
00075     MulCost = 1
00076   };
00077 
00078   EIGEN_DEVICE_FUNC static inline Real epsilon() { return 0; }
00079   EIGEN_DEVICE_FUNC static inline Real dummy_precision() { return 0; }
00080   EIGEN_DEVICE_FUNC static inline Real highest() { return n; }
00081   EIGEN_DEVICE_FUNC static inline Real lowest() { return n; }
00082 };
00083 
00084 namespace internal {
00085 template <typename T>
00086 EIGEN_DEVICE_FUNC void update_value(T& val, DenseIndex new_val) {
00087   val = new_val;
00088 }
00089 template <DenseIndex n>
00090 EIGEN_DEVICE_FUNC void update_value(type2index<n>& val, DenseIndex new_val) {
00091   val.set(new_val);
00092 }
00093 
00094 template <typename T>
00095 EIGEN_DEVICE_FUNC void update_value(T& val, IndexPair<DenseIndex> new_val) {
00096   val = new_val;
00097 }
00098 template <DenseIndex f, DenseIndex s>
00099 EIGEN_DEVICE_FUNC void update_value(type2indexpair<f, s>& val, IndexPair<DenseIndex> new_val) {
00100   val.set(new_val);
00101 }
00102 
00103 
00104 template <typename T>
00105 struct is_compile_time_constant {
00106   static constexpr bool value = false;
00107 };
00108 
00109 template <DenseIndex idx>
00110 struct is_compile_time_constant<type2index<idx> > {
00111   static constexpr bool value = true;
00112 };
00113 template <DenseIndex idx>
00114 struct is_compile_time_constant<const type2index<idx> > {
00115   static constexpr bool value = true;
00116 };
00117 template <DenseIndex idx>
00118 struct is_compile_time_constant<type2index<idx>& > {
00119   static constexpr bool value = true;
00120 };
00121 template <DenseIndex idx>
00122 struct is_compile_time_constant<const type2index<idx>& > {
00123   static constexpr bool value = true;
00124 };
00125 
00126 template <DenseIndex f, DenseIndex s>
00127 struct is_compile_time_constant<type2indexpair<f, s> > {
00128   static constexpr bool value = true;
00129 };
00130 template <DenseIndex f, DenseIndex s>
00131 struct is_compile_time_constant<const type2indexpair<f, s> > {
00132   static constexpr bool value = true;
00133 };
00134 template <DenseIndex f, DenseIndex s>
00135 struct is_compile_time_constant<type2indexpair<f, s>& > {
00136   static constexpr bool value = true;
00137 };
00138 template <DenseIndex f, DenseIndex s>
00139 struct is_compile_time_constant<const type2indexpair<f, s>& > {
00140   static constexpr bool value = true;
00141 };
00142 
00143 
00144 template<typename... T>
00145 struct IndexTuple;
00146 
00147 template<typename T, typename... O>
00148 struct IndexTuple<T, O...> {
00149   EIGEN_DEVICE_FUNC constexpr IndexTuple() : head(), others() { }
00150   EIGEN_DEVICE_FUNC constexpr IndexTuple(const T& v, const O... o) : head(v), others(o...) { }
00151 
00152   constexpr static int count = 1 + sizeof...(O);
00153   T head;
00154   IndexTuple<O...> others;
00155   typedef T Head;
00156   typedef IndexTuple<O...> Other;
00157 };
00158 
00159 template<typename T>
00160   struct IndexTuple<T> {
00161   EIGEN_DEVICE_FUNC constexpr IndexTuple() : head() { }
00162   EIGEN_DEVICE_FUNC constexpr IndexTuple(const T& v) : head(v) { }
00163 
00164   constexpr static int count = 1;
00165   T head;
00166   typedef T Head;
00167 };
00168 
00169 
00170 template<int N, typename... T>
00171 struct IndexTupleExtractor;
00172 
00173 template<int N, typename T, typename... O>
00174 struct IndexTupleExtractor<N, T, O...> {
00175 
00176   typedef typename IndexTupleExtractor<N-1, O...>::ValType ValType;
00177 
00178   EIGEN_DEVICE_FUNC static constexpr ValType& get_val(IndexTuple<T, O...>& val) {
00179     return IndexTupleExtractor<N-1, O...>::get_val(val.others);
00180   }
00181 
00182   EIGEN_DEVICE_FUNC static constexpr const ValType& get_val(const IndexTuple<T, O...>& val) {
00183     return IndexTupleExtractor<N-1, O...>::get_val(val.others);
00184   }
00185   template <typename V>
00186   EIGEN_DEVICE_FUNC static void set_val(IndexTuple<T, O...>& val, V& new_val) {
00187     IndexTupleExtractor<N-1, O...>::set_val(val.others, new_val);
00188   }
00189 
00190 };
00191 
00192 template<typename T, typename... O>
00193   struct IndexTupleExtractor<0, T, O...> {
00194 
00195   typedef T ValType;
00196 
00197   EIGEN_DEVICE_FUNC static constexpr ValType& get_val(IndexTuple<T, O...>& val) {
00198     return val.head;
00199   }
00200   EIGEN_DEVICE_FUNC static constexpr const ValType& get_val(const IndexTuple<T, O...>& val) {
00201     return val.head;
00202   }
00203   template <typename V>
00204   EIGEN_DEVICE_FUNC static void set_val(IndexTuple<T, O...>& val, V& new_val) {
00205     val.head = new_val;
00206   }
00207 };
00208 
00209 
00210 
00211 template <int N, typename T, typename... O>
00212 EIGEN_DEVICE_FUNC constexpr typename IndexTupleExtractor<N, T, O...>::ValType& array_get(IndexTuple<T, O...>& tuple) {
00213   return IndexTupleExtractor<N, T, O...>::get_val(tuple);
00214 }
00215 template <int N, typename T, typename... O>
00216 EIGEN_DEVICE_FUNC constexpr const typename IndexTupleExtractor<N, T, O...>::ValType& array_get(const IndexTuple<T, O...>& tuple) {
00217   return IndexTupleExtractor<N, T, O...>::get_val(tuple);
00218 }
00219 template <typename T, typename... O>
00220   struct array_size<IndexTuple<T, O...> > {
00221   static const size_t value = IndexTuple<T, O...>::count;
00222 };
00223 template <typename T, typename... O>
00224   struct array_size<const IndexTuple<T, O...> > {
00225   static const size_t value = IndexTuple<T, O...>::count;
00226 };
00227 
00228 
00229 
00230 
00231 template <DenseIndex Idx, typename ValueT>
00232 struct tuple_coeff {
00233   template <typename... T>
00234   EIGEN_DEVICE_FUNC static constexpr ValueT get(const DenseIndex i, const IndexTuple<T...>& t) {
00235     //    return array_get<Idx>(t) * (i == Idx) + tuple_coeff<Idx-1>::get(i, t) * (i != Idx);
00236     return (i == Idx ? array_get<Idx>(t) : tuple_coeff<Idx-1, ValueT>::get(i, t));
00237   }
00238   template <typename... T>
00239   EIGEN_DEVICE_FUNC static void set(const DenseIndex i, IndexTuple<T...>& t, const ValueT& value) {
00240     if (i == Idx) {
00241       update_value(array_get<Idx>(t), value);
00242     } else {
00243       tuple_coeff<Idx-1, ValueT>::set(i, t, value);
00244     }
00245   }
00246 
00247   template <typename... T>
00248   EIGEN_DEVICE_FUNC static constexpr bool value_known_statically(const DenseIndex i, const IndexTuple<T...>& t) {
00249     return ((i == Idx) & is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value) ||
00250         tuple_coeff<Idx-1, ValueT>::value_known_statically(i, t);
00251   }
00252 
00253   template <typename... T>
00254   EIGEN_DEVICE_FUNC static constexpr bool values_up_to_known_statically(const IndexTuple<T...>& t) {
00255     return is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value &&
00256         tuple_coeff<Idx-1, ValueT>::values_up_to_known_statically(t);
00257   }
00258 
00259   template <typename... T>
00260   EIGEN_DEVICE_FUNC static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple<T...>& t) {
00261     return is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value &&
00262            is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value &&
00263            array_get<Idx>(t) > array_get<Idx-1>(t) &&
00264            tuple_coeff<Idx-1, ValueT>::values_up_to_statically_known_to_increase(t);
00265   }
00266 };
00267 
00268 template <typename ValueT>
00269 struct tuple_coeff<0, ValueT> {
00270   template <typename... T>
00271   EIGEN_DEVICE_FUNC static constexpr ValueT get(const DenseIndex /*i*/, const IndexTuple<T...>& t) {
00272     //  eigen_assert (i == 0);  // gcc fails to compile assertions in constexpr
00273     return array_get<0>(t)/* * (i == 0)*/;
00274   }
00275   template <typename... T>
00276   EIGEN_DEVICE_FUNC static void set(const DenseIndex i, IndexTuple<T...>& t, const ValueT value) {
00277     eigen_assert (i == 0);
00278     update_value(array_get<0>(t), value);
00279   }
00280   template <typename... T>
00281   EIGEN_DEVICE_FUNC static constexpr bool value_known_statically(const DenseIndex i, const IndexTuple<T...>&) {
00282     return is_compile_time_constant<typename IndexTupleExtractor<0, T...>::ValType>::value & (i == 0);
00283   }
00284 
00285   template <typename... T>
00286   EIGEN_DEVICE_FUNC static constexpr bool values_up_to_known_statically(const IndexTuple<T...>&) {
00287     return is_compile_time_constant<typename IndexTupleExtractor<0, T...>::ValType>::value;
00288   }
00289 
00290   template <typename... T>
00291   EIGEN_DEVICE_FUNC static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple<T...>&) {
00292     return true;
00293   }
00294 };
00295 }  // namespace internal
00296 
00297 
00298 
00299 template<typename FirstType, typename... OtherTypes>
00300 struct IndexList : internal::IndexTuple<FirstType, OtherTypes...> {
00301   EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr DenseIndex operator[] (const DenseIndex i) const {
00302     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::get(i, *this);
00303   }
00304   EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr DenseIndex get(const DenseIndex i) const {
00305     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::get(i, *this);
00306   }
00307   EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void set(const DenseIndex i, const DenseIndex value) {
00308     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::set(i, *this, value);
00309   }
00310 
00311   EIGEN_DEVICE_FUNC constexpr IndexList(const internal::IndexTuple<FirstType, OtherTypes...>& other) : internal::IndexTuple<FirstType, OtherTypes...>(other) { }
00312   EIGEN_DEVICE_FUNC constexpr IndexList(FirstType& first, OtherTypes... other) : internal::IndexTuple<FirstType, OtherTypes...>(first, other...) { }
00313   EIGEN_DEVICE_FUNC constexpr IndexList() : internal::IndexTuple<FirstType, OtherTypes...>() { }
00314 
00315   EIGEN_DEVICE_FUNC constexpr bool value_known_statically(const DenseIndex i) const {
00316     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::value_known_statically(i, *this);
00317   }
00318   EIGEN_DEVICE_FUNC constexpr bool all_values_known_statically() const {
00319     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::values_up_to_known_statically(*this);
00320   }
00321 
00322   EIGEN_DEVICE_FUNC constexpr bool values_statically_known_to_increase() const {
00323     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::values_up_to_statically_known_to_increase(*this);
00324   }
00325 };
00326 
00327 
00328 template<typename FirstType, typename... OtherTypes>
00329 constexpr IndexList<FirstType, OtherTypes...> make_index_list(FirstType val1, OtherTypes... other_vals) {
00330   return IndexList<FirstType, OtherTypes...>(val1, other_vals...);
00331 }
00332 
00333 
00334 template<typename FirstType, typename... OtherTypes>
00335 struct IndexPairList : internal::IndexTuple<FirstType, OtherTypes...> {
00336   EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr IndexPair<DenseIndex> operator[] (const DenseIndex i) const {
00337     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, IndexPair<DenseIndex>>::get(i, *this);
00338   }
00339   EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void set(const DenseIndex i, const IndexPair<DenseIndex> value) {
00340     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...>>::value-1, IndexPair<DenseIndex> >::set(i, *this, value);
00341   }
00342 
00343   EIGEN_DEVICE_FUNC  constexpr IndexPairList(const internal::IndexTuple<FirstType, OtherTypes...>& other) : internal::IndexTuple<FirstType, OtherTypes...>(other) { }
00344   EIGEN_DEVICE_FUNC  constexpr IndexPairList() : internal::IndexTuple<FirstType, OtherTypes...>() { }
00345 
00346   EIGEN_DEVICE_FUNC constexpr bool value_known_statically(const DenseIndex i) const {
00347     return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, DenseIndex>::value_known_statically(i, *this);
00348   }
00349 };
00350 
00351 namespace internal {
00352 
00353 template<typename FirstType, typename... OtherTypes> size_t array_prod(const IndexList<FirstType, OtherTypes...>& sizes) {
00354   size_t result = 1;
00355   for (int i = 0; i < array_size<IndexList<FirstType, OtherTypes...> >::value; ++i) {
00356     result *= sizes[i];
00357   }
00358   return result;
00359 }
00360 
00361 template<typename FirstType, typename... OtherTypes> struct array_size<IndexList<FirstType, OtherTypes...> > {
00362   static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value;
00363 };
00364 template<typename FirstType, typename... OtherTypes> struct array_size<const IndexList<FirstType, OtherTypes...> > {
00365   static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value;
00366 };
00367 
00368 template<typename FirstType, typename... OtherTypes> struct array_size<IndexPairList<FirstType, OtherTypes...> > {
00369   static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value;
00370 };
00371 template<typename FirstType, typename... OtherTypes> struct array_size<const IndexPairList<FirstType, OtherTypes...> > {
00372   static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value;
00373 };
00374 
00375 template<DenseIndex N, typename FirstType, typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr DenseIndex array_get(IndexList<FirstType, OtherTypes...>& a) {
00376   return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a);
00377 }
00378 template<DenseIndex N, typename FirstType, typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr DenseIndex array_get(const IndexList<FirstType, OtherTypes...>& a) {
00379   return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a);
00380 }
00381 
00382 template <typename T>
00383 struct index_known_statically_impl {
00384   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex) {
00385     return false;
00386   }
00387 };
00388 
00389 template <typename FirstType, typename... OtherTypes>
00390 struct index_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
00391   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i) {
00392     return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
00393   }
00394 };
00395 
00396 template <typename FirstType, typename... OtherTypes>
00397 struct index_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
00398   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i) {
00399     return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
00400   }
00401 };
00402 
00403 
00404 template <typename T>
00405 struct all_indices_known_statically_impl {
00406   static constexpr bool run() {
00407     return false;
00408   }
00409 };
00410 
00411 template <typename FirstType, typename... OtherTypes>
00412 struct all_indices_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
00413   EIGEN_DEVICE_FUNC static constexpr bool run() {
00414     return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
00415   }
00416 };
00417 
00418 template <typename FirstType, typename... OtherTypes>
00419 struct all_indices_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
00420   EIGEN_DEVICE_FUNC static constexpr bool run() {
00421     return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
00422   }
00423 };
00424 
00425 
00426 template <typename T>
00427 struct indices_statically_known_to_increase_impl {
00428   EIGEN_DEVICE_FUNC static constexpr bool run() {
00429     return false;
00430   }
00431 };
00432 
00433 template <typename FirstType, typename... OtherTypes>
00434   struct indices_statically_known_to_increase_impl<IndexList<FirstType, OtherTypes...> > {
00435   EIGEN_DEVICE_FUNC static constexpr bool run() {
00436     return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
00437   }
00438 };
00439 
00440 template <typename FirstType, typename... OtherTypes>
00441   struct indices_statically_known_to_increase_impl<const IndexList<FirstType, OtherTypes...> > {
00442   EIGEN_DEVICE_FUNC static constexpr bool run() {
00443     return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
00444   }
00445 };
00446 
00447 
00448 template <typename Tx>
00449 struct index_statically_eq_impl {
00450   EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
00451     return false;
00452   }
00453 };
00454 
00455 template <typename FirstType, typename... OtherTypes>
00456 struct index_statically_eq_impl<IndexList<FirstType, OtherTypes...> > {
00457   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00458     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00459         (IndexList<FirstType, OtherTypes...>().get(i) == value);
00460   }
00461 };
00462 
00463 template <typename FirstType, typename... OtherTypes>
00464 struct index_statically_eq_impl<const IndexList<FirstType, OtherTypes...> > {
00465   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00466     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00467         (IndexList<FirstType, OtherTypes...>().get(i) == value);
00468   }
00469 };
00470 
00471 
00472 template <typename T>
00473 struct index_statically_ne_impl {
00474   EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
00475     return false;
00476   }
00477 };
00478 
00479 template <typename FirstType, typename... OtherTypes>
00480 struct index_statically_ne_impl<IndexList<FirstType, OtherTypes...> > {
00481   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00482     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00483         (IndexList<FirstType, OtherTypes...>().get(i) != value);
00484   }
00485 };
00486 
00487 template <typename FirstType, typename... OtherTypes>
00488 struct index_statically_ne_impl<const IndexList<FirstType, OtherTypes...> > {
00489   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00490     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00491         (IndexList<FirstType, OtherTypes...>().get(i) != value);
00492   }
00493 };
00494 
00495 
00496 template <typename T>
00497 struct index_statically_gt_impl {
00498   EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
00499     return false;
00500   }
00501 };
00502 
00503 template <typename FirstType, typename... OtherTypes>
00504 struct index_statically_gt_impl<IndexList<FirstType, OtherTypes...> > {
00505   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00506     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00507         (IndexList<FirstType, OtherTypes...>().get(i) > value);
00508   }
00509 };
00510 
00511 template <typename FirstType, typename... OtherTypes>
00512 struct index_statically_gt_impl<const IndexList<FirstType, OtherTypes...> > {
00513   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00514     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00515         (IndexList<FirstType, OtherTypes...>().get(i) > value);
00516   }
00517 };
00518 
00519 
00520 
00521 template <typename T>
00522 struct index_statically_lt_impl {
00523   EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
00524     return false;
00525   }
00526 };
00527 
00528 template <typename FirstType, typename... OtherTypes>
00529 struct index_statically_lt_impl<IndexList<FirstType, OtherTypes...> > {
00530   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00531     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00532         (IndexList<FirstType, OtherTypes...>().get(i) < value);
00533   }
00534 };
00535 
00536 template <typename FirstType, typename... OtherTypes>
00537 struct index_statically_lt_impl<const IndexList<FirstType, OtherTypes...> > {
00538   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00539     return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
00540         (IndexList<FirstType, OtherTypes...>().get(i) < value);
00541   }
00542 };
00543 
00544 
00545 
00546 template <typename Tx>
00547 struct index_pair_first_statically_eq_impl {
00548   EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
00549     return false;
00550   }
00551 };
00552 
00553 template <typename FirstType, typename... OtherTypes>
00554 struct index_pair_first_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
00555   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00556     return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
00557         (IndexPairList<FirstType, OtherTypes...>().operator[](i).first == value);
00558   }
00559 };
00560 
00561 template <typename FirstType, typename... OtherTypes>
00562 struct index_pair_first_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
00563   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00564     return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
00565         (IndexPairList<FirstType, OtherTypes...>().operator[](i).first == value);
00566   }
00567 };
00568 
00569 
00570 
00571 template <typename Tx>
00572 struct index_pair_second_statically_eq_impl {
00573   EIGEN_DEVICE_FUNC static constexpr bool run(DenseIndex, DenseIndex) {
00574     return false;
00575   }
00576 };
00577 
00578 template <typename FirstType, typename... OtherTypes>
00579 struct index_pair_second_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
00580   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00581     return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
00582         (IndexPairList<FirstType, OtherTypes...>().operator[](i).second == value);
00583   }
00584 };
00585 
00586 template <typename FirstType, typename... OtherTypes>
00587 struct index_pair_second_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
00588   EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) {
00589     return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &
00590         (IndexPairList<FirstType, OtherTypes...>().operator[](i).second == value);
00591   }
00592 };
00593 
00594 
00595 }  // end namespace internal
00596 }  // end namespace Eigen
00597 
00598 #else
00599 
00600 namespace Eigen {
00601 namespace internal {
00602 
00603 template <typename T>
00604 struct index_known_statically_impl {
00605   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex) {
00606     return false;
00607   }
00608 };
00609 
00610 template <typename T>
00611 struct all_indices_known_statically_impl {
00612   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() {
00613     return false;
00614   }
00615 };
00616 
00617 template <typename T>
00618 struct indices_statically_known_to_increase_impl {
00619   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() {
00620     return false;
00621   }
00622 };
00623 
00624 template <typename T>
00625 struct index_statically_eq_impl {
00626   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
00627     return false;
00628   }
00629 };
00630 
00631 template <typename T>
00632 struct index_statically_ne_impl {
00633   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
00634     return false;
00635   }
00636 };
00637 
00638 template <typename T>
00639 struct index_statically_gt_impl {
00640   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
00641     return false;
00642   }
00643 };
00644 
00645 template <typename T>
00646 struct index_statically_lt_impl {
00647   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
00648     return false;
00649   }
00650 };
00651 
00652 template <typename Tx>
00653 struct index_pair_first_statically_eq_impl {
00654   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
00655     return false;
00656   }
00657 };
00658 
00659 template <typename Tx>
00660 struct index_pair_second_statically_eq_impl {
00661   static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(DenseIndex, DenseIndex) {
00662     return false;
00663   }
00664 };
00665 
00666 
00667 
00668 }  // end namespace internal
00669 }  // end namespace Eigen
00670 
00671 #endif
00672 
00673 
00674 namespace Eigen {
00675 namespace internal {
00676 template <typename T>
00677 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_known_statically(DenseIndex i) {
00678   return index_known_statically_impl<T>::run(i);
00679 }
00680 
00681 template <typename T>
00682 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool all_indices_known_statically() {
00683   return all_indices_known_statically_impl<T>::run();
00684 }
00685 
00686 template <typename T>
00687 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool indices_statically_known_to_increase() {
00688   return indices_statically_known_to_increase_impl<T>::run();
00689 }
00690 
00691 template <typename T>
00692 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_eq(DenseIndex i, DenseIndex value) {
00693   return index_statically_eq_impl<T>::run(i, value);
00694 }
00695 
00696 template <typename T>
00697 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_ne(DenseIndex i, DenseIndex value) {
00698   return index_statically_ne_impl<T>::run(i, value);
00699 }
00700 
00701 template <typename T>
00702 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_gt(DenseIndex i, DenseIndex value) {
00703   return index_statically_gt_impl<T>::run(i, value);
00704 }
00705 
00706 template <typename T>
00707 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_lt(DenseIndex i, DenseIndex value) {
00708   return index_statically_lt_impl<T>::run(i, value);
00709 }
00710 
00711 template <typename T>
00712 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_first_statically_eq(DenseIndex i, DenseIndex value) {
00713   return index_pair_first_statically_eq_impl<T>::run(i, value);
00714 }
00715 
00716 template <typename T>
00717 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_second_statically_eq(DenseIndex i, DenseIndex value) {
00718   return index_pair_second_statically_eq_impl<T>::run(i, value);
00719 }
00720 
00721 }  // end namespace internal
00722 }  // end namespace Eigen
00723 
00724 
00725 #endif // EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
 All Classes Functions Variables Typedefs Enumerator