10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H
48 template <Index f, Index s>
84 val = internal::convert_index<T>(new_val);
95 template <Index f, Index s>
101 template <
typename T>
102 struct is_compile_time_constant {
103 static constexpr
bool value =
false;
107 struct is_compile_time_constant<type2index<idx> > {
108 static constexpr
bool value =
true;
111 struct is_compile_time_constant<const type2index<idx> > {
112 static constexpr
bool value =
true;
115 struct is_compile_time_constant<type2index<idx>& > {
116 static constexpr
bool value =
true;
119 struct is_compile_time_constant<const type2index<idx>& > {
120 static constexpr
bool value =
true;
123 template <Index f, Index s>
124 struct is_compile_time_constant<type2indexpair<f, s> > {
125 static constexpr
bool value =
true;
127 template <Index f, Index s>
128 struct is_compile_time_constant<const type2indexpair<f, s> > {
129 static constexpr
bool value =
true;
131 template <Index f, Index s>
132 struct is_compile_time_constant<type2indexpair<f, s>& > {
133 static constexpr
bool value =
true;
135 template <Index f, Index s>
136 struct is_compile_time_constant<const type2indexpair<f, s>& > {
137 static constexpr
bool value =
true;
141 template<
typename...
T>
144 template<
typename T,
typename... O>
145 struct IndexTuple<
T, O...> {
149 constexpr
static int count = 1 +
sizeof...(O);
151 IndexTuple<O...> others;
153 typedef IndexTuple<O...> Other;
157 struct IndexTuple<
T> {
161 constexpr
static int count = 1;
167 template<
int N,
typename...
T>
168 struct IndexTupleExtractor;
170 template<
int N,
typename T,
typename... O>
171 struct IndexTupleExtractor<N,
T, O...> {
173 typedef typename IndexTupleExtractor<N-1, O...>::ValType ValType;
176 return IndexTupleExtractor<N-1, O...>::get_val(val.others);
179 EIGEN_DEVICE_FUNC static constexpr
const ValType& get_val(
const IndexTuple<T, O...>& val) {
180 return IndexTupleExtractor<N-1, O...>::get_val(val.others);
182 template <
typename V>
184 IndexTupleExtractor<N-1, O...>::set_val(val.others, new_val);
189 template<
typename T,
typename... O>
190 struct IndexTupleExtractor<0,
T, O...> {
197 EIGEN_DEVICE_FUNC static constexpr
const ValType& get_val(
const IndexTuple<T, O...>& val) {
200 template <
typename V>
208 template <
int N,
typename T,
typename... O>
210 return IndexTupleExtractor<N, T, O...>::get_val(tuple);
212 template <
int N,
typename T,
typename... O>
214 return IndexTupleExtractor<N, T, O...>::get_val(tuple);
216 template <
typename T,
typename... O>
217 struct array_size<IndexTuple<
T, O...> > {
218 static const size_t value = IndexTuple<
T, O...>::count;
220 template <
typename T,
typename... O>
221 struct array_size<const IndexTuple<
T, O...> > {
222 static const size_t value = IndexTuple<
T, O...>::count;
228 template <Index Idx,
typename ValueT>
230 template <
typename...
T>
233 return (i == Idx ? array_get<Idx>(t) : tuple_coeff<Idx-1, ValueT>::get(i, t));
235 template <
typename...
T>
240 tuple_coeff<Idx-1, ValueT>::set(i, t, value);
244 template <
typename...
T>
245 EIGEN_DEVICE_FUNC static constexpr
bool value_known_statically(
const Index i,
const IndexTuple<T...>& t) {
246 return ((i == Idx) && is_compile_time_constant<
typename IndexTupleExtractor<Idx, T...>::ValType>::value) ||
247 tuple_coeff<Idx-1, ValueT>::value_known_statically(i, t);
250 template <
typename...
T>
251 EIGEN_DEVICE_FUNC static constexpr
bool values_up_to_known_statically(
const IndexTuple<T...>& t) {
252 return is_compile_time_constant<
typename IndexTupleExtractor<Idx,
T...>::ValType>::value &&
253 tuple_coeff<Idx-1, ValueT>::values_up_to_known_statically(t);
256 template <
typename...
T>
257 EIGEN_DEVICE_FUNC static constexpr
bool values_up_to_statically_known_to_increase(
const IndexTuple<T...>& t) {
258 return is_compile_time_constant<
typename IndexTupleExtractor<Idx,
T...>::ValType>::value &&
259 is_compile_time_constant<
typename IndexTupleExtractor<Idx,
T...>::ValType>::value &&
260 array_get<Idx>(t) >
array_get<Idx-1>(t) &&
261 tuple_coeff<Idx-1, ValueT>::values_up_to_statically_known_to_increase(t);
265 template <
typename ValueT>
266 struct tuple_coeff<0, ValueT> {
267 template <
typename...
T>
270 return array_get<0>(t);
272 template <
typename...
T>
277 template <
typename...
T>
279 return is_compile_time_constant<
typename IndexTupleExtractor<0,
T...>::ValType>::value && (
i == 0);
282 template <
typename...
T>
283 EIGEN_DEVICE_FUNC static constexpr
bool values_up_to_known_statically(
const IndexTuple<T...>&) {
284 return is_compile_time_constant<
typename IndexTupleExtractor<0,
T...>::ValType>::value;
287 template <
typename...
T>
288 EIGEN_DEVICE_FUNC static constexpr
bool values_up_to_statically_known_to_increase(
const IndexTuple<T...>&) {
296 template<
typename FirstType,
typename... OtherTypes>
297 struct IndexList : internal::IndexTuple<FirstType, OtherTypes...> {
299 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
Index>
::get(
i, *
this);
302 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
Index>
::get(
i, *
this);
305 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
Index>
::set(
i, *
this, value);
309 return 1 +
sizeof...(OtherTypes);
318 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
Index>
::value_known_statically(
i, *
this);
321 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
Index>::values_up_to_known_statically(*
this);
325 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
Index>::values_up_to_statically_known_to_increase(*
this);
329 template <
typename FirstType,
typename... OtherTypes>
333 for (
size_t i = 0;
i < 1 +
sizeof...(OtherTypes); ++
i) {
334 if (
i > 0) os <<
", ";
341 template<
typename FirstType,
typename... OtherTypes>
343 return IndexList<FirstType, OtherTypes...>(val1, other_vals...);
347 template<
typename FirstType,
typename... OtherTypes>
350 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
IndexPair<Index>>::get(
i, *
this);
353 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...>>::value-1,
IndexPair<Index> >
::set(
i, *
this, value);
360 return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1,
Index>
::value_known_statically(
i, *
this);
366 template<
typename FirstType,
typename... OtherTypes>
370 for (
size_t i = 0;
i < array_size<
IndexList<FirstType, OtherTypes...> >::value; ++
i) {
376 template<
typename FirstType,
typename... OtherTypes>
struct array_size<
IndexList<FirstType, OtherTypes...> > {
377 static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value;
379 template<
typename FirstType,
typename... OtherTypes>
struct array_size<const IndexList<FirstType, OtherTypes...> > {
380 static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value;
383 template<
typename FirstType,
typename... OtherTypes>
struct array_size<IndexPairList<FirstType, OtherTypes...> > {
384 static const size_t value = 1 +
sizeof...(OtherTypes);
386 template<
typename FirstType,
typename... OtherTypes>
struct array_size<const IndexPairList<FirstType, OtherTypes...> > {
387 static const size_t value = 1 +
sizeof...(OtherTypes);
391 return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(
a);
394 return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(
a);
397 template <
typename T>
398 struct index_known_statically_impl {
404 template <
typename FirstType,
typename... OtherTypes>
405 struct index_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
407 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
411 template <
typename FirstType,
typename... OtherTypes>
412 struct index_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
414 return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
419 template <
typename T>
420 struct all_indices_known_statically_impl {
421 static constexpr
bool run() {
426 template <
typename FirstType,
typename... OtherTypes>
427 struct all_indices_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
429 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
433 template <
typename FirstType,
typename... OtherTypes>
434 struct all_indices_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
436 return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
441 template <
typename T>
442 struct indices_statically_known_to_increase_impl {
448 template <
typename FirstType,
typename... OtherTypes>
449 struct indices_statically_known_to_increase_impl<IndexList<FirstType, OtherTypes...> > {
451 return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
455 template <
typename FirstType,
typename... OtherTypes>
456 struct indices_statically_known_to_increase_impl<const IndexList<FirstType, OtherTypes...> > {
458 return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase();
463 template <
typename Tx>
464 struct index_statically_eq_impl {
470 template <
typename FirstType,
typename... OtherTypes>
471 struct index_statically_eq_impl<IndexList<FirstType, OtherTypes...> > {
473 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
474 (IndexList<FirstType, OtherTypes...>().get(i) == value);
478 template <
typename FirstType,
typename... OtherTypes>
479 struct index_statically_eq_impl<const IndexList<FirstType, OtherTypes...> > {
481 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
482 (IndexList<FirstType, OtherTypes...>().get(i) == value);
487 template <
typename T>
488 struct index_statically_ne_impl {
494 template <
typename FirstType,
typename... OtherTypes>
495 struct index_statically_ne_impl<IndexList<FirstType, OtherTypes...> > {
497 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
498 (IndexList<FirstType, OtherTypes...>().get(i) != value);
502 template <
typename FirstType,
typename... OtherTypes>
503 struct index_statically_ne_impl<const IndexList<FirstType, OtherTypes...> > {
505 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
506 (IndexList<FirstType, OtherTypes...>().get(i) != value);
511 template <
typename T>
512 struct index_statically_gt_impl {
518 template <
typename FirstType,
typename... OtherTypes>
519 struct index_statically_gt_impl<IndexList<FirstType, OtherTypes...> > {
521 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
522 (IndexList<FirstType, OtherTypes...>().get(i) > value);
526 template <
typename FirstType,
typename... OtherTypes>
527 struct index_statically_gt_impl<const IndexList<FirstType, OtherTypes...> > {
529 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
530 (IndexList<FirstType, OtherTypes...>().get(i) > value);
536 template <
typename T>
537 struct index_statically_lt_impl {
543 template <
typename FirstType,
typename... OtherTypes>
544 struct index_statically_lt_impl<IndexList<FirstType, OtherTypes...> > {
546 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
547 (IndexList<FirstType, OtherTypes...>().get(i) < value);
551 template <
typename FirstType,
typename... OtherTypes>
552 struct index_statically_lt_impl<const IndexList<FirstType, OtherTypes...> > {
554 return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &&
555 (IndexList<FirstType, OtherTypes...>().get(i) < value);
561 template <
typename Tx>
562 struct index_pair_first_statically_eq_impl {
568 template <
typename FirstType,
typename... OtherTypes>
569 struct index_pair_first_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
571 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &&
572 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).first == value);
576 template <
typename FirstType,
typename... OtherTypes>
577 struct index_pair_first_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
579 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &&
580 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).first == value);
586 template <
typename Tx>
587 struct index_pair_second_statically_eq_impl {
593 template <
typename FirstType,
typename... OtherTypes>
594 struct index_pair_second_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > {
596 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &&
597 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).second == value);
601 template <
typename FirstType,
typename... OtherTypes>
602 struct index_pair_second_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > {
604 return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) &&
605 (IndexPairList<FirstType, OtherTypes...>().
operator[](i).second == value);
616 template <
typename T>
618 return index_known_statically_impl<T>::run(
i);
621 template <
typename T>
623 return all_indices_known_statically_impl<T>::run();
626 template <
typename T>
628 return indices_statically_known_to_increase_impl<T>::run();
631 template <
typename T>
633 return index_statically_eq_impl<T>::run(
i, value);
636 template <
typename T>
638 return index_statically_ne_impl<T>::run(
i, value);
641 template <
typename T>
643 return index_statically_gt_impl<T>::run(
i, value);
646 template <
typename T>
648 return index_statically_lt_impl<T>::run(
i, value);
651 template <
typename T>
653 return index_pair_first_statically_eq_impl<T>::run(
i, value);
656 template <
typename T>
658 return index_pair_second_statically_eq_impl<T>::run(
i, value);
Array< int, Dynamic, 1 > v
FixedSegmentReturnType< N >::Type head(Index n=N)
#define EIGEN_UNROLL_LOOP
#define EIGEN_DEVICE_FUNC
static EIGEN_CONSTEXPR bool index_statically_ne(Index i, Index value)
static EIGEN_CONSTEXPR bool all_indices_known_statically()
static EIGEN_CONSTEXPR bool indices_statically_known_to_increase()
static EIGEN_CONSTEXPR bool index_statically_gt(Index i, Index value)
constexpr T array_get(const numeric_list< T, a, as... > &)
void update_value(T &val, Index new_val)
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
static EIGEN_CONSTEXPR bool index_statically_eq(Index i, Index value)
static EIGEN_CONSTEXPR bool index_pair_first_statically_eq(Index i, Index value)
static EIGEN_CONSTEXPR bool index_pair_second_statically_eq(Index i, Index value)
static EIGEN_CONSTEXPR bool index_statically_lt(Index i, Index value)
static EIGEN_CONSTEXPR bool index_known_statically(Index i)
constexpr auto array_prod(const array< T, N > &arr) -> decltype(array_reduce< product_op, T, N >(arr, static_cast< T >(1)))
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
std::ostream & operator<<(std::ostream &s, const DiagonalBase< Derived > &m)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
constexpr IndexList< FirstType, OtherTypes... > make_index_list(FirstType val1, OtherTypes... other_vals)
constexpr IndexList(const internal::IndexTuple< FirstType, OtherTypes... > &other)
constexpr Index get(const Index i) const
void set(const Index i, const Index value)
constexpr bool value_known_statically(const Index i) const
constexpr bool all_values_known_statically() const
constexpr bool values_statically_known_to_increase() const
constexpr std::size_t size() const
constexpr IndexList(FirstType &first, OtherTypes... other)
constexpr Index operator[](const Index i) const
constexpr IndexPairList()
constexpr IndexPairList(const internal::IndexTuple< FirstType, OtherTypes... > &other)
void set(const Index i, const IndexPair< Index > value)
constexpr IndexPair< Index > operator[](const Index i) const
constexpr bool value_known_statically(const Index i) const
static EIGEN_CONSTEXPR Real highest()
static EIGEN_CONSTEXPR Real epsilon()
static EIGEN_CONSTEXPR Real dummy_precision()
static EIGEN_CONSTEXPR Real lowest()
void set(const IndexPair< Index > &val)
static const Index second