10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
13 #if defined(EIGEN_HAS_CONSTEXPR) && defined(EIGEN_HAS_VARIADIC_TEMPLATES)
15 #define EIGEN_HAS_INDEX_LIST
39 template <DenseIndex n>
41 static const DenseIndex value = n;
42 constexpr
operator DenseIndex()
const {
return n; }
43 void set(DenseIndex val) {
44 eigen_assert(val == n);
50 void update_value(T& val, DenseIndex new_val) {
53 template <DenseIndex n>
54 void update_value(type2index<n>& val, DenseIndex new_val) {
59 struct is_compile_time_constant {
60 static constexpr
bool value =
false;
63 template <DenseIndex
idx>
64 struct is_compile_time_constant<type2index<idx> > {
65 static constexpr
bool value =
true;
67 template <DenseIndex
idx>
68 struct is_compile_time_constant<const type2index<idx> > {
69 static constexpr
bool value =
true;
71 template <DenseIndex
idx>
72 struct is_compile_time_constant<type2index<idx>& > {
73 static constexpr
bool value =
true;
75 template <DenseIndex
idx>
76 struct is_compile_time_constant<const type2index<idx>& > {
77 static constexpr
bool value =
true;
80 template <DenseIndex Idx>
82 template <
typename... T>
83 static constexpr DenseIndex
get(
const DenseIndex i,
const std::tuple<T...>& t) {
84 return std::get<Idx>(t) * (i == Idx) + tuple_coeff<Idx-1>::get(i, t) * (i != Idx);
86 template <
typename... T>
87 static void set(
const DenseIndex i, std::tuple<T...>& t,
const DenseIndex value) {
89 update_value(std::get<Idx>(t), value);
91 tuple_coeff<Idx-1>::set(i, t, value);
95 template <
typename... T>
96 static constexpr
bool value_known_statically(
const DenseIndex i,
const std::tuple<T...>& t) {
97 return ((i == Idx) & is_compile_time_constant<
typename std::tuple_element<Idx, std::tuple<T...> >::type>::value) ||
98 tuple_coeff<Idx-1>::value_known_statically(i, t);
101 template <
typename... T>
102 static constexpr
bool values_up_to_known_statically(
const std::tuple<T...>& t) {
103 return is_compile_time_constant<
typename std::tuple_element<Idx, std::tuple<T...> >::type>::value &&
104 tuple_coeff<Idx-1>::values_up_to_known_statically(t);
107 template <
typename... T>
108 static constexpr
bool values_up_to_statically_known_to_increase(
const std::tuple<T...>& t) {
109 return is_compile_time_constant<
typename std::tuple_element<Idx, std::tuple<T...> >::type>::value &&
110 is_compile_time_constant<
typename std::tuple_element<Idx-1, std::tuple<T...> >::type>::value &&
111 std::get<Idx>(t) > std::get<Idx-1>(t) &&
112 tuple_coeff<Idx-1>::values_up_to_statically_known_to_increase(t);
117 struct tuple_coeff<0> {
118 template <
typename... T>
119 static constexpr DenseIndex
get(
const DenseIndex i,
const std::tuple<T...>& t) {
121 return std::get<0>(t) * (i == 0);
123 template <
typename... T>
124 static void set(
const DenseIndex i, std::tuple<T...>& t,
const DenseIndex value) {
125 eigen_assert (i == 0);
126 update_value(std::get<0>(t), value);
128 template <
typename... T>
129 static constexpr
bool value_known_statically(
const DenseIndex i,
const std::tuple<T...>&) {
131 return is_compile_time_constant<
typename std::tuple_element<0, std::tuple<T...> >::type>::value & (i == 0);
134 template <
typename... T>
135 static constexpr
bool values_up_to_known_statically(
const std::tuple<T...>&) {
136 return is_compile_time_constant<
typename std::tuple_element<0, std::tuple<T...> >::type>::value;
139 template <
typename... T>
140 static constexpr
bool values_up_to_statically_known_to_increase(
const std::tuple<T...>&) {
147 template<
typename FirstType,
typename... OtherTypes>
148 struct IndexList : std::tuple<FirstType, OtherTypes...> {
149 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr DenseIndex operator[] (
const DenseIndex i)
const {
150 return internal::tuple_coeff<std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value-1>::get(i, *
this);
152 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
void set(
const DenseIndex i,
const DenseIndex value) {
153 return internal::tuple_coeff<std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value-1>::set(i, *
this, value);
156 constexpr IndexList(
const std::tuple<FirstType, OtherTypes...>& other) : std::tuple<FirstType, OtherTypes...>(other) { }
157 constexpr IndexList() : std::tuple<FirstType, OtherTypes...>() { }
159 constexpr
bool value_known_statically(
const DenseIndex i)
const {
160 return internal::tuple_coeff<std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value-1>::value_known_statically(i, *
this);
162 constexpr
bool all_values_known_statically()
const {
163 return internal::tuple_coeff<std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value-1>::values_up_to_known_statically(*
this);
166 constexpr
bool values_statically_known_to_increase()
const {
167 return internal::tuple_coeff<std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value-1>::values_up_to_statically_known_to_increase(*
this);
172 template<
typename FirstType,
typename... OtherTypes>
173 constexpr IndexList<FirstType, OtherTypes...> make_index_list(FirstType val1, OtherTypes... other_vals) {
174 return std::make_tuple(val1, other_vals...);
180 template<
typename FirstType,
typename... OtherTypes>
size_t array_prod(
const IndexList<FirstType, OtherTypes...>& sizes) {
182 for (
int i = 0; i < array_size<IndexList<FirstType, OtherTypes...> >::value; ++i) {
188 template<
typename FirstType,
typename... OtherTypes>
struct array_size<IndexList<FirstType, OtherTypes...> > {
189 static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value;
191 template<
typename FirstType,
typename... OtherTypes>
struct array_size<const IndexList<FirstType, OtherTypes...> > {
192 static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value;
195 template<DenseIndex n,
typename FirstType,
typename... OtherTypes> constexpr DenseIndex array_get(IndexList<FirstType, OtherTypes...>& a) {
196 return std::get<n>(a);
198 template<DenseIndex n,
typename FirstType,
typename... OtherTypes> constexpr DenseIndex array_get(
const IndexList<FirstType, OtherTypes...>& a) {
199 return std::get<n>(a);
202 template <
typename T>
203 struct index_known_statically {
204 constexpr
bool operator() (DenseIndex)
const {
209 template <
typename FirstType,
typename... OtherTypes>
210 struct index_known_statically<IndexList<FirstType, OtherTypes...> > {
211 constexpr
bool operator() (
const DenseIndex i)
const {
212 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
216 template <
typename FirstType,
typename... OtherTypes>
217 struct index_known_statically<const IndexList<FirstType, OtherTypes...> > {
218 constexpr
bool operator() (
const DenseIndex i)
const {
219 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
223 template <
typename T>
224 struct all_indices_known_statically {
225 constexpr
bool operator() ()
const {
230 template <
typename FirstType,
typename... OtherTypes>
231 struct all_indices_known_statically<IndexList<FirstType, OtherTypes...> > {
232 constexpr
bool operator() ()
const {
233 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
237 template <
typename FirstType,
typename... OtherTypes>
238 struct all_indices_known_statically<const IndexList<FirstType, OtherTypes...> > {
239 constexpr
bool operator() ()
const {
240 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
244 template <
typename T>
245 struct indices_statically_known_to_increase {
246 constexpr
bool operator() ()
const {
251 template <
typename FirstType,
typename... OtherTypes>
252 struct indices_statically_known_to_increase<IndexList<FirstType, OtherTypes...> > {
253 constexpr
bool operator() ()
const {
254 return IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
258 template <
typename FirstType,
typename... OtherTypes>
259 struct indices_statically_known_to_increase<const IndexList<FirstType, OtherTypes...> > {
260 constexpr
bool operator() ()
const {
261 return IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
265 template <
typename Tx>
266 struct index_statically_eq {
267 constexpr
bool operator() (DenseIndex, DenseIndex)
const {
272 template <
typename FirstType,
typename... OtherTypes>
273 struct index_statically_eq<IndexList<FirstType, OtherTypes...> > {
274 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
275 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
276 (IndexList<FirstType, OtherTypes...>()[i] == value);
280 template <
typename FirstType,
typename... OtherTypes>
281 struct index_statically_eq<const IndexList<FirstType, OtherTypes...> > {
282 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
283 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
284 (IndexList<FirstType, OtherTypes...>()[i] == value);
288 template <
typename T>
289 struct index_statically_ne {
290 constexpr
bool operator() (DenseIndex, DenseIndex)
const {
295 template <
typename FirstType,
typename... OtherTypes>
296 struct index_statically_ne<IndexList<FirstType, OtherTypes...> > {
297 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
298 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
299 (IndexList<FirstType, OtherTypes...>()[i] != value);
303 template <
typename FirstType,
typename... OtherTypes>
304 struct index_statically_ne<const IndexList<FirstType, OtherTypes...> > {
305 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
306 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
307 (IndexList<FirstType, OtherTypes...>()[i] != value);
312 template <
typename T>
313 struct index_statically_gt {
314 constexpr
bool operator() (DenseIndex, DenseIndex)
const {
319 template <
typename FirstType,
typename... OtherTypes>
320 struct index_statically_gt<IndexList<FirstType, OtherTypes...> > {
321 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
322 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
323 (IndexList<FirstType, OtherTypes...>()[i] > value);
327 template <
typename FirstType,
typename... OtherTypes>
328 struct index_statically_gt<const IndexList<FirstType, OtherTypes...> > {
329 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
330 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
331 (IndexList<FirstType, OtherTypes...>()[i] > value);
335 template <
typename T>
336 struct index_statically_lt {
337 constexpr
bool operator() (DenseIndex, DenseIndex)
const {
342 template <
typename FirstType,
typename... OtherTypes>
343 struct index_statically_lt<IndexList<FirstType, OtherTypes...> > {
344 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
345 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
346 (IndexList<FirstType, OtherTypes...>()[i] < value);
350 template <
typename FirstType,
typename... OtherTypes>
351 struct index_statically_lt<const IndexList<FirstType, OtherTypes...> > {
352 constexpr
bool operator() (
const DenseIndex i,
const DenseIndex value)
const {
353 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
354 (IndexList<FirstType, OtherTypes...>()[i] < value);
367 template <
typename T>
368 struct index_known_statically {
369 EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC
bool operator() (DenseIndex)
const{
374 template <
typename T>
375 struct all_indices_known_statically {
376 EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC
bool operator() ()
const {
381 template <
typename T>
382 struct indices_statically_known_to_increase {
383 EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC
bool operator() ()
const {
388 template <
typename T>
389 struct index_statically_eq {
390 EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC
bool operator() (DenseIndex, DenseIndex)
const{
395 template <
typename T>
396 struct index_statically_ne {
397 EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC
bool operator() (DenseIndex, DenseIndex)
const{
402 template <
typename T>
403 struct index_statically_gt {
404 EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC
bool operator() (DenseIndex, DenseIndex)
const{
409 template <
typename T>
410 struct index_statically_lt {
411 EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC
bool operator() (DenseIndex, DenseIndex)
const{
421 #endif // EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13