44 #ifndef Intrepid2_FunctorIterator_h
45 #define Intrepid2_FunctorIterator_h
55 template<
typename FunctorType,
typename ScalarType,
int rank>
59 template<
typename FunctorType,
typename ScalarType>
62 using return_type = decltype(std::declval<FunctorType>().
operator()());
63 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
65 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
69 template<
typename FunctorType,
typename ScalarType>
72 using return_type = decltype(std::declval<FunctorType>().
operator()(0));
73 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
75 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
79 template<
typename FunctorType,
typename ScalarType>
82 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0));
83 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
85 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
89 template<
typename FunctorType,
typename ScalarType>
92 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0));
93 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
95 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
99 template<
typename FunctorType,
typename ScalarType>
102 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0));
103 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
105 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
109 template<
typename FunctorType,
typename ScalarType>
112 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0,0));
113 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
115 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
119 template<
typename FunctorType,
typename ScalarType>
122 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0,0,0));
123 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
125 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
129 template<
typename FunctorType,
typename ScalarType>
132 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0,0,0,0));
133 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
135 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
139 template<
class FunctorType,
typename ScalarType,
int rank>
142 const FunctorType &functor_;
143 Kokkos::Array<int,7> dims_;
144 Kokkos::Array<int,7> index_;
148 KOKKOS_INLINE_FUNCTION
153 for (
int d=0; d<rank; d++)
155 dims_[d] = functor.extent_int(d);
158 for (
int d=rank; d<7; d++)
165 using return_type =
typename std::conditional< functor_returns_ref<FunctorType, ScalarType, rank>::value,
const ScalarType &,
const ScalarType>::type;
167 template<
bool B,
class T = return_type >
168 using enable_if_t =
typename std::enable_if<B,T>::type;
172 template<
int M = rank>
174 KOKKOS_INLINE_FUNCTION
182 template<
int M = rank>
184 KOKKOS_INLINE_FUNCTION
187 return functor_(index_[0]);
192 template<
int M = rank>
194 KOKKOS_INLINE_FUNCTION
197 return functor_(index_[0], index_[1]);
202 template<
int M = rank>
204 KOKKOS_INLINE_FUNCTION
207 return functor_(index_[0], index_[1], index_[2]);
212 template<
int M = rank>
214 KOKKOS_INLINE_FUNCTION
217 return functor_(index_[0], index_[1], index_[2], index_[3]);
222 template<
int M = rank>
224 KOKKOS_INLINE_FUNCTION
227 return functor_(index_[0], index_[1], index_[2], index_[3], index_[4]);
233 template<
int M = rank>
235 KOKKOS_INLINE_FUNCTION
238 return functor_(index_[0], index_[1], index_[2], index_[3], index_[4], index_[5]);
243 template<
int M = rank>
245 KOKKOS_INLINE_FUNCTION
248 return functor_(index_[0], index_[1], index_[2], index_[3], index_[4], index_[5], index_[6]);
253 KOKKOS_INLINE_FUNCTION
256 for (
int r=rank-1; r>=0; r--)
258 if (index_[r]+1 < dims_[r])
269 KOKKOS_INLINE_FUNCTION
272 for (
int r=rank-1; r>=0; r--)
274 if (index_[r]+1 < dims_[r])
293 KOKKOS_INLINE_FUNCTION
296 for (
int r=rank-1; r>=0; r--)
298 if (index_[r]-1 >= 0)
306 index_[r] = dims_[r]-1;
318 KOKKOS_INLINE_FUNCTION
322 for (
int d=0; d<7; d++)
324 if (d>0) index_1D *= dims_[d-1];
325 index_1D += index_[d];
333 KOKKOS_INLINE_FUNCTION
336 Kokkos::Array<int,7> location;
337 int remainder = enumerationIndex;
338 for (
int d=6; d>=0; d--)
340 location[d] = remainder % dims_[d];
341 remainder /= dims_[d];
350 KOKKOS_INLINE_FUNCTION
353 return index_[dimension];
359 KOKKOS_INLINE_FUNCTION
362 return dims_[dimension];
367 KOKKOS_INLINE_FUNCTION
368 void reset(
unsigned from_rank_number=0)
370 for (
unsigned d=from_rank_number; d<functor_.rank(); d++)
378 KOKKOS_INLINE_FUNCTION
387 KOKKOS_INLINE_FUNCTION
395 KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION int increment()
KOKKOS_INLINE_FUNCTION bool decrement()
KOKKOS_INLINE_FUNCTION void reset(unsigned from_rank_number=0)
KOKKOS_INLINE_FUNCTION Kokkos::Array< int, 7 > & getLocation()
KOKKOS_INLINE_FUNCTION int getIndex(int dimension)
essentially, a read-only variant of ViewIterator, for a general functor (extent_int() and rank() supp...
SFINAE helper to detect whether a functor returns a reference type.
KOKKOS_INLINE_FUNCTION void setEnumerationIndex(const int &enumerationIndex)
KOKKOS_INLINE_FUNCTION FunctorIterator(const FunctorType &functor)
KOKKOS_INLINE_FUNCTION void setLocation(const Kokkos::Array< int, 7 > &location)
KOKKOS_INLINE_FUNCTION int getExtent(int dimension)
KOKKOS_INLINE_FUNCTION void setLocationInDim(const int &dim, const int &i)
KOKKOS_INLINE_FUNCTION int nextIncrementRank()
KOKKOS_INLINE_FUNCTION int getEnumerationIndex()