42 if (
u <
l)
yakl_throw(
"ERROR: cannot specify an upper bound < lower bound");
51 if (
u <
l)
yakl_throw(
"ERROR: cannot specify an upper bound < lower bound");
52 if (
s < 1)
yakl_throw(
"ERROR: negative strides not yet supported.");
79 template <
int N,
bool simple = false>
class Bounds;
92 template<
int N>
class Bounds<N,true> {
104 if constexpr (N >= 1) dims[0] = b0;
105 if constexpr (N >= 2) dims[1] = b1;
106 if constexpr (N >= 3) dims[2] = b2;
107 if constexpr (N >= 4) dims[3] = b3;
108 if constexpr (N >= 5) dims[4] = b4;
109 if constexpr (N >= 6) dims[5] = b5;
110 if constexpr (N >= 7) dims[6] = b6;
111 if constexpr (N >= 8) dims[7] = b7;
113 if (N >= 2) {
if (b1 == 0)
yakl_throw(
"ERROR: Too few bounds specified"); }
114 if (N >= 3) {
if (b2 == 0)
yakl_throw(
"ERROR: Too few bounds specified"); }
115 if (N >= 4) {
if (b3 == 0)
yakl_throw(
"ERROR: Too few bounds specified"); }
116 if (N >= 5) {
if (b4 == 0)
yakl_throw(
"ERROR: Too few bounds specified"); }
117 if (N >= 6) {
if (b5 == 0)
yakl_throw(
"ERROR: Too few bounds specified"); }
118 if (N >= 7) {
if (b6 == 0)
yakl_throw(
"ERROR: Too few bounds specified"); }
119 if (N >= 8) {
if (b7 == 0)
yakl_throw(
"ERROR: Too few bounds specified"); }
121 if (b1 > 0) num_bounds++;
122 if (b2 > 0) num_bounds++;
123 if (b3 > 0) num_bounds++;
124 if (b4 > 0) num_bounds++;
125 if (b5 > 0) num_bounds++;
126 if (b6 > 0) num_bounds++;
127 if (b7 > 0) num_bounds++;
128 if (num_bounds != N)
yakl_throw(
"ERROR: Number of bounds passed does not match templated number of bounds.");
131 for (
int i=0; i<N; i++) { nIter *= dims[i]; }
136 if (i < 0 || i > N-1)
yakl_throw(
"ERROR: Calling lbound() on an out of bounds integer");
143 if (i < 0 || i > N-1)
yakl_throw(
"ERROR: Calling dim() on an out of bounds integer");
150 if (i < 0 || i > N-1)
yakl_throw(
"ERROR: Calling stride() on an out of bounds integer");
156 if constexpr (N == 1) {
158 }
else if constexpr (N == 2) {
159 indices[0] = iGlob/dims[1] ;
160 indices[1] = iGlob - dims[1]*indices[0];
161 }
else if constexpr (N == 3) {
163 fac = dims[1]*dims[2]; indices[0] = iGlob / fac;
164 term = indices[0]*fac; fac = dims[2]; indices[1] = (iGlob - term) / fac;
165 term += indices[1]*fac; indices[2] = iGlob - term ;
166 }
else if constexpr (N == 4) {
168 fac = dims[1]*dims[2]*dims[3]; indices[0] = iGlob / fac;
169 term = indices[0]*fac; fac = dims[2]*dims[3]; indices[1] = (iGlob - term) / fac;
170 term += indices[1]*fac; fac = dims[3]; indices[2] = (iGlob - term) / fac;
171 term += indices[2]*fac; indices[3] = iGlob - term ;
172 }
else if constexpr (N == 5) {
174 fac = dims[1]*dims[2]*dims[3]*dims[4]; indices[0] = iGlob / fac;
175 term = indices[0]*fac; fac = dims[2]*dims[3]*dims[4]; indices[1] = (iGlob - term) / fac;
176 term += indices[1]*fac; fac = dims[3]*dims[4]; indices[2] = (iGlob - term) / fac;
177 term += indices[2]*fac; fac = dims[4]; indices[3] = (iGlob - term) / fac;
178 term += indices[3]*fac; indices[4] = iGlob - term ;
179 }
else if constexpr (N == 6) {
180 index_t term, fac4=dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
181 indices[0] = iGlob / fac0;
182 term = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
183 term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
184 term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
185 term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
186 term += indices[4]*fac4; indices[5] = iGlob - term ;
187 }
else if constexpr (N == 7) {
188 index_t term, fac5=dims[6], fac4=fac5*dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
189 indices[0] = iGlob / fac0;
190 term = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
191 term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
192 term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
193 term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
194 term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
195 term += indices[5]*fac5; indices[6] = iGlob - term ;
196 }
else if constexpr (N == 8) {
197 index_t term, fac6=dims[7], fac5=fac6*dims[6], fac4=fac5*dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
198 indices[0] = iGlob / fac0;
199 term = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
200 term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
201 term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
202 term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
203 term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
204 term += indices[5]*fac5; indices[6] = (iGlob - term) / fac6;
205 term += indices[6]*fac6; indices[7] = iGlob - term ;
207 if constexpr (N >= 1) indices[0]++;
208 if constexpr (N >= 2) indices[1]++;
209 if constexpr (N >= 3) indices[2]++;
210 if constexpr (N >= 4) indices[3]++;
211 if constexpr (N >= 5) indices[4]++;
212 if constexpr (N >= 6) indices[5]++;
213 if constexpr (N >= 7) indices[6]++;
214 if constexpr (N >= 8) indices[7]++;
255 if constexpr (N >= 1) { lbounds[0] = b0.
l; strides[0] = b0.
s; dims[0] = ( b0.
u - b0.
l + 1 ) / b0.
s; }
256 if constexpr (N >= 2) { lbounds[1] = b1.l; strides[1] = b1.s; dims[1] = ( b1.u - b1.l + 1 ) / b1.s; }
257 if constexpr (N >= 3) { lbounds[2] = b2.l; strides[2] = b2.s; dims[2] = ( b2.u - b2.l + 1 ) / b2.s; }
258 if constexpr (N >= 4) { lbounds[3] = b3.l; strides[3] = b3.s; dims[3] = ( b3.u - b3.l + 1 ) / b3.s; }
259 if constexpr (N >= 5) { lbounds[4] = b4.l; strides[4] = b4.s; dims[4] = ( b4.u - b4.l + 1 ) / b4.s; }
260 if constexpr (N >= 6) { lbounds[5] = b5.l; strides[5] = b5.s; dims[5] = ( b5.u - b5.l + 1 ) / b5.s; }
261 if constexpr (N >= 7) { lbounds[6] = b6.l; strides[6] = b6.s; dims[6] = ( b6.u - b6.l + 1 ) / b6.s; }
262 if constexpr (N >= 8) { lbounds[7] = b7.l; strides[7] = b7.s; dims[7] = ( b7.u - b7.l + 1 ) / b7.s; }
264 if (N >= 2) {
if (! b1.valid())
yakl_throw(
"ERROR: Too few bounds specified"); }
265 if (N >= 3) {
if (! b2.valid())
yakl_throw(
"ERROR: Too few bounds specified"); }
266 if (N >= 4) {
if (! b3.valid())
yakl_throw(
"ERROR: Too few bounds specified"); }
267 if (N >= 5) {
if (! b4.valid())
yakl_throw(
"ERROR: Too few bounds specified"); }
268 if (N >= 6) {
if (! b5.valid())
yakl_throw(
"ERROR: Too few bounds specified"); }
269 if (N >= 7) {
if (! b6.valid())
yakl_throw(
"ERROR: Too few bounds specified"); }
270 if (N >= 8) {
if (! b7.valid())
yakl_throw(
"ERROR: Too few bounds specified"); }
272 if (b1.valid()) num_bounds++;
273 if (b2.valid()) num_bounds++;
274 if (b3.valid()) num_bounds++;
275 if (b4.valid()) num_bounds++;
276 if (b5.valid()) num_bounds++;
277 if (b6.valid()) num_bounds++;
278 if (b7.valid()) num_bounds++;
279 if (num_bounds != N)
yakl_throw(
"ERROR: Number of bounds passed does not match templated number of bounds.");
282 for (
int i=0; i<N; i++) { nIter *= dims[i]; }
287 if (i < 0 || i > N-1)
yakl_throw(
"ERROR: Calling lbound() on an out of bounds integer");
294 if (i < 0 || i > N-1)
yakl_throw(
"ERROR: Calling dim() on an out of bounds integer");
301 if (i < 0 || i > N-1)
yakl_throw(
"ERROR: Calling stride() on an out of bounds integer");
308 if constexpr (N == 1) {
310 }
else if constexpr (N == 2) {
311 indices[0] = iGlob/dims[1] ;
312 indices[1] = iGlob - dims[1]*indices[0];
313 }
else if constexpr (N == 3) {
315 fac = dims[1]*dims[2]; indices[0] = iGlob / fac;
316 term = indices[0]*fac; fac = dims[2]; indices[1] = (iGlob - term) / fac;
317 term += indices[1]*fac; indices[2] = iGlob - term ;
318 }
else if constexpr (N == 4) {
320 fac = dims[1]*dims[2]*dims[3]; indices[0] = iGlob / fac;
321 term = indices[0]*fac; fac = dims[2]*dims[3]; indices[1] = (iGlob - term) / fac;
322 term += indices[1]*fac; fac = dims[3]; indices[2] = (iGlob - term) / fac;
323 term += indices[2]*fac; indices[3] = iGlob - term ;
324 }
else if constexpr (N == 5) {
326 fac = dims[1]*dims[2]*dims[3]*dims[4]; indices[0] = iGlob / fac;
327 term = indices[0]*fac; fac = dims[2]*dims[3]*dims[4]; indices[1] = (iGlob - term) / fac;
328 term += indices[1]*fac; fac = dims[3]*dims[4]; indices[2] = (iGlob - term) / fac;
329 term += indices[2]*fac; fac = dims[4]; indices[3] = (iGlob - term) / fac;
330 term += indices[3]*fac; indices[4] = iGlob - term ;
331 }
else if constexpr (N == 6) {
332 index_t term, fac4=dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
333 indices[0] = iGlob / fac0;
334 term = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
335 term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
336 term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
337 term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
338 term += indices[4]*fac4; indices[5] = iGlob - term ;
339 }
else if constexpr (N == 7) {
340 index_t term, fac5=dims[6], fac4=fac5*dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
341 indices[0] = iGlob / fac0;
342 term = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
343 term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
344 term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
345 term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
346 term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
347 term += indices[5]*fac5; indices[6] = iGlob - term ;
348 }
else if constexpr (N == 8) {
349 index_t term, fac6=dims[7], fac5=fac6*dims[6], fac4=fac5*dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
350 indices[0] = iGlob / fac0;
351 term = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
352 term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
353 term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
354 term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
355 term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
356 term += indices[5]*fac5; indices[6] = (iGlob - term) / fac6;
357 term += indices[6]*fac6; indices[7] = iGlob - term ;
361 if constexpr (N >= 1) indices[0] = indices[0]*strides[0] + lbounds[0];
362 if constexpr (N >= 2) indices[1] = indices[1]*strides[1] + lbounds[1];
363 if constexpr (N >= 3) indices[2] = indices[2]*strides[2] + lbounds[2];
364 if constexpr (N >= 4) indices[3] = indices[3]*strides[3] + lbounds[3];
365 if constexpr (N >= 5) indices[4] = indices[4]*strides[4] + lbounds[4];
366 if constexpr (N >= 6) indices[5] = indices[5]*strides[5] + lbounds[5];
367 if constexpr (N >= 7) indices[6] = indices[6]*strides[6] + lbounds[6];
368 if constexpr (N >= 8) indices[7] = indices[7]*strides[7] + lbounds[7];