9 template <
unsigned Dim>
10 template <
class... Args,
typename std::enable_if<
sizeof...(Args) == Dim,
bool>::type>
11 KOKKOS_FUNCTION NDIndex<Dim>::NDIndex(
const Args&... args)
12 : indices_m{args...} {}
14 template <
unsigned Dim>
16 for (
unsigned int d = 0; d < Dim; ++d) {
17 indices_m[d] = Index(sizes[d]);
21 template <
unsigned Dim>
26 template <
unsigned Dim>
31 template <
unsigned Dim>
33 unsigned s = indices_m[0].
length();
34 for (
unsigned int d = 1; d < Dim; ++d) {
35 s *= indices_m[d].length();
40 template <
unsigned Dim>
43 for (
unsigned d = 0; d < Dim; ++d) {
44 r = r || indices_m[d].empty();
49 template <
unsigned Dim>
50 inline std::ostream& operator<<(std::ostream& out,
const NDIndex<Dim>& idx) {
52 for (
unsigned d = 0; d < Dim; ++d) {
53 out << idx[d] << ((d == Dim - 1) ?
'}' :
',');
58 template <
unsigned Dim>
61 for (
unsigned d = 0; d < Dim; ++d) {
67 template <
unsigned Dim>
70 for (
unsigned d = 0; d < Dim; ++d) {
71 r[d] = indices_m[d].
grow(ncells);
76 template <
unsigned Dim>
79 r[dim] = indices_m[dim].
grow(ncells);
83 template <
unsigned Dim>
84 KOKKOS_INLINE_FUNCTION
bool NDIndex<Dim>::touches(
const NDIndex<Dim>& a)
const {
86 for (
unsigned int d = 0; (d < Dim) && touch; ++d) {
87 touch = touch && indices_m[d].touches(a.indices_m[d]);
92 template <
unsigned Dim>
93 KOKKOS_INLINE_FUNCTION
bool NDIndex<Dim>::contains(
const NDIndex<Dim>& a)
const {
95 for (
unsigned int d = 0; (d < Dim) && cont; ++d) {
96 cont = cont && indices_m[d].contains(a.indices_m[d]);
101 template <
unsigned Dim>
102 KOKKOS_INLINE_FUNCTION
bool NDIndex<Dim>::split(NDIndex<Dim>& l, NDIndex<Dim>& r,
unsigned d,
110 return indices_m[d].split(l[d], r[d], i);
113 template <
unsigned Dim>
114 KOKKOS_INLINE_FUNCTION
bool NDIndex<Dim>::split(NDIndex<Dim>& l, NDIndex<Dim>& r,
unsigned d,
122 return indices_m[d].split(l[d], r[d], a);
125 template <
unsigned Dim>
126 KOKKOS_INLINE_FUNCTION
bool NDIndex<Dim>::split(NDIndex<Dim>& l, NDIndex<Dim>& r,
134 return indices_m[d].split(l[d], r[d]);
137 template <
unsigned Dim>
138 KOKKOS_INLINE_FUNCTION
bool NDIndex<Dim>::split(NDIndex<Dim>& l, NDIndex<Dim>& r)
const {
139 unsigned int max_dim = 0;
140 unsigned int max_length = 0;
141 for (
unsigned int d = 0; d < Dim; ++d) {
142 if (indices_m[d].length() > max_length) {
144 max_length = indices_m[d].length();
147 return split(l, r, max_dim);
150 template <
unsigned Dim>
153 for (
unsigned d = 0; d < Dim; ++d) {
154 result[d] = indices_m[d].length();
159 template <
unsigned Dim>
162 for (
unsigned d = 0; d < Dim; ++d) {
163 result[d] = indices_m[d].first();
168 template <
unsigned Dim>
171 for (
unsigned d = 0; d < Dim; ++d) {
172 result[d] = indices_m[d].last();
177 template <
unsigned Dim>
178 KOKKOS_INLINE_FUNCTION
constexpr typename NDIndex<Dim>::iterator NDIndex<Dim>::begin() {
182 template <
unsigned Dim>
183 KOKKOS_INLINE_FUNCTION
constexpr typename NDIndex<Dim>::iterator NDIndex<Dim>::end() {
184 return indices_m + Dim;
187 template <
unsigned Dim>
188 KOKKOS_INLINE_FUNCTION
constexpr typename NDIndex<Dim>::const_iterator NDIndex<Dim>::begin()
193 template <
unsigned Dim>
194 KOKKOS_INLINE_FUNCTION
constexpr typename NDIndex<Dim>::const_iterator NDIndex<Dim>::end()
196 return indices_m + Dim;
199 template <
unsigned Dim>
200 bool operator==(
const NDIndex<Dim>& nd1,
const NDIndex<Dim>& nd2) {
201 for (
unsigned d = 0; d < Dim; d++) {
202 if (nd1[d] != nd2[d]) {
209 template <
unsigned Dim>
210 bool operator!=(
const NDIndex<Dim>& nd1,
const NDIndex<Dim>& nd2) {
211 return !(nd1 == nd2);
KOKKOS_INLINE_FUNCTION size_t length() const noexcept
Definition Index.hpp:88
KOKKOS_INLINE_FUNCTION bool empty() const noexcept
Definition NDIndex.hpp:41
KOKKOS_INLINE_FUNCTION unsigned size() const noexcept
Definition NDIndex.hpp:32
KOKKOS_INLINE_FUNCTION const ippl::Index & operator[](unsigned d) const noexcept
Definition NDIndex.hpp:22
KOKKOS_INLINE_FUNCTION NDIndex< Dim > intersect(const NDIndex< Dim > &) const
Definition NDIndex.hpp:59
KOKKOS_INLINE_FUNCTION NDIndex< Dim > grow(int ncells) const
Definition NDIndex.hpp:68