11 #ifndef Intrepid2_FunctorIterator_h
12 #define Intrepid2_FunctorIterator_h
22 template<
typename FunctorType,
typename ScalarType,
int rank>
26 template<
typename FunctorType,
typename ScalarType>
29 using return_type = decltype(std::declval<FunctorType>().
operator()());
30 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
32 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
36 template<
typename FunctorType,
typename ScalarType>
39 using return_type = decltype(std::declval<FunctorType>().
operator()(0));
40 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
42 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
46 template<
typename FunctorType,
typename ScalarType>
49 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0));
50 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
52 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
56 template<
typename FunctorType,
typename ScalarType>
59 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0));
60 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
62 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
66 template<
typename FunctorType,
typename ScalarType>
69 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0));
70 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
72 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
76 template<
typename FunctorType,
typename ScalarType>
79 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0,0));
80 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
82 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
86 template<
typename FunctorType,
typename ScalarType>
89 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0,0,0));
90 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
92 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
96 template<
typename FunctorType,
typename ScalarType>
99 using return_type = decltype(std::declval<FunctorType>().
operator()(0,0,0,0,0,0,0));
100 using return_type_no_ref =
typename std::remove_reference<return_type>::type;
102 static constexpr
bool value = !std::is_same<return_type, return_type_no_ref>::value;
106 template<
class FunctorType,
typename ScalarType,
int rank>
109 const FunctorType &functor_;
110 Kokkos::Array<int,7> dims_;
111 Kokkos::Array<int,7> index_;
115 KOKKOS_INLINE_FUNCTION
120 for (
int d=0; d<rank; d++)
122 dims_[d] = functor.extent_int(d);
125 for (
int d=rank; d<7; d++)
132 using return_type =
typename std::conditional< functor_returns_ref<FunctorType, ScalarType, rank>::value,
const ScalarType &,
const ScalarType>::type;
134 template<
bool B,
class T = return_type >
135 using enable_if_t =
typename std::enable_if<B,T>::type;
139 template<
int M = rank>
141 KOKKOS_INLINE_FUNCTION
149 template<
int M = rank>
151 KOKKOS_INLINE_FUNCTION
154 return functor_(index_[0]);
159 template<
int M = rank>
161 KOKKOS_INLINE_FUNCTION
164 return functor_(index_[0], index_[1]);
169 template<
int M = rank>
171 KOKKOS_INLINE_FUNCTION
174 return functor_(index_[0], index_[1], index_[2]);
179 template<
int M = rank>
181 KOKKOS_INLINE_FUNCTION
184 return functor_(index_[0], index_[1], index_[2], index_[3]);
189 template<
int M = rank>
191 KOKKOS_INLINE_FUNCTION
194 return functor_(index_[0], index_[1], index_[2], index_[3], index_[4]);
200 template<
int M = rank>
202 KOKKOS_INLINE_FUNCTION
205 return functor_(index_[0], index_[1], index_[2], index_[3], index_[4], index_[5]);
210 template<
int M = rank>
212 KOKKOS_INLINE_FUNCTION
215 return functor_(index_[0], index_[1], index_[2], index_[3], index_[4], index_[5], index_[6]);
220 KOKKOS_INLINE_FUNCTION
223 for (
int r=rank-1; r>=0; r--)
225 if (index_[r]+1 < dims_[r])
236 KOKKOS_INLINE_FUNCTION
239 for (
int r=rank-1; r>=0; r--)
241 if (index_[r]+1 < dims_[r])
260 KOKKOS_INLINE_FUNCTION
263 for (
int r=rank-1; r>=0; r--)
265 if (index_[r]-1 >= 0)
273 index_[r] = dims_[r]-1;
285 KOKKOS_INLINE_FUNCTION
289 for (
int d=0; d<7; d++)
291 if (d>0) index_1D *= dims_[d-1];
292 index_1D += index_[d];
300 KOKKOS_INLINE_FUNCTION
303 Kokkos::Array<int,7> location;
304 int remainder = enumerationIndex;
305 for (
int d=6; d>=0; d--)
307 location[d] = remainder % dims_[d];
308 remainder /= dims_[d];
317 KOKKOS_INLINE_FUNCTION
320 return index_[dimension];
326 KOKKOS_INLINE_FUNCTION
329 return dims_[dimension];
334 KOKKOS_INLINE_FUNCTION
335 void reset(
unsigned from_rank_number=0)
337 for (
unsigned d=from_rank_number; d<functor_.rank(); d++)
345 KOKKOS_INLINE_FUNCTION
354 KOKKOS_INLINE_FUNCTION
362 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()