48         if (
u < 
l) 
yakl_throw(
"ERROR: cannot specify an upper bound < lower bound");
 
   57         if (
u < 
l) 
yakl_throw(
"ERROR: cannot specify an upper bound < lower bound");
 
   58         if (
s < 1) 
yakl_throw(
"ERROR: negative strides not yet supported.");
 
   84   template <
int N, 
bool simple = false> 
class Bounds;
 
   97   template<
int N> 
class Bounds<N,true> {
 
  109       if constexpr (N >= 1) dims[0] = b0;
 
  110       if constexpr (N >= 2) dims[1] = b1;
 
  111       if constexpr (N >= 3) dims[2] = b2;
 
  112       if constexpr (N >= 4) dims[3] = b3;
 
  113       if constexpr (N >= 5) dims[4] = b4;
 
  114       if constexpr (N >= 6) dims[5] = b5;
 
  115       if constexpr (N >= 7) dims[6] = b6;
 
  116       if constexpr (N >= 8) dims[7] = b7;
 
  118         if (N >= 2) { 
if (b1 == 0) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  119         if (N >= 3) { 
if (b2 == 0) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  120         if (N >= 4) { 
if (b3 == 0) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  121         if (N >= 5) { 
if (b4 == 0) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  122         if (N >= 6) { 
if (b5 == 0) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  123         if (N >= 7) { 
if (b6 == 0) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  124         if (N >= 8) { 
if (b7 == 0) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  126         if (b1 > 0) num_bounds++;
 
  127         if (b2 > 0) num_bounds++;
 
  128         if (b3 > 0) num_bounds++;
 
  129         if (b4 > 0) num_bounds++;
 
  130         if (b5 > 0) num_bounds++;
 
  131         if (b6 > 0) num_bounds++;
 
  132         if (b7 > 0) num_bounds++;
 
  133         if (num_bounds != N) 
yakl_throw(
"ERROR: Number of bounds passed does not match templated number of bounds.");
 
  136       for (
int i=0; i<N; i++) { nIter *= dims[i]; }
 
  141         if (i < 0 || i > N-1) 
yakl_throw(
"ERROR: Calling lbound() on an out of bounds integer");
 
  148         if (i < 0 || i > N-1) 
yakl_throw(
"ERROR: Calling dim() on an out of bounds integer");
 
  155         if (i < 0 || i > N-1) 
yakl_throw(
"ERROR: Calling stride() on an out of bounds integer");
 
  161       if constexpr        (N == 1) {
 
  163       } 
else if constexpr (N == 2) {
 
  164         indices[0] = iGlob/dims[1];
 
  165         indices[1] = iGlob - dims[1]*indices[0];
 
  166       } 
else if constexpr (N == 3) {
 
  168                                 fac = dims[1]*dims[2]; indices[0] =  iGlob         / fac;
 
  169         term  = indices[0]*fac; fac =         dims[2]; indices[1] = (iGlob - term) / fac;
 
  170         term += indices[1]*fac;                        indices[2] =  iGlob - term;
 
  171       } 
else if constexpr (N == 4) {
 
  173                                 fac = dims[1]*dims[2]*dims[3]; indices[0] =  iGlob         / fac;
 
  174         term  = indices[0]*fac; fac =         dims[2]*dims[3]; indices[1] = (iGlob - term) / fac;
 
  175         term += indices[1]*fac; fac =                 dims[3]; indices[2] = (iGlob - term) / fac;
 
  176         term += indices[2]*fac;                                indices[3] =  iGlob - term;
 
  177       } 
else if constexpr (N == 5) {
 
  179                                 fac = dims[1]*dims[2]*dims[3]*dims[4]; indices[0] =  iGlob         / fac;
 
  180         term  = indices[0]*fac; fac =         dims[2]*dims[3]*dims[4]; indices[1] = (iGlob - term) / fac;
 
  181         term += indices[1]*fac; fac =                 dims[3]*dims[4]; indices[2] = (iGlob - term) / fac;
 
  182         term += indices[2]*fac; fac =                         dims[4]; indices[3] = (iGlob - term) / fac;
 
  183         term += indices[3]*fac;                                        indices[4] =  iGlob - term;
 
  184       } 
else if constexpr (N == 6) {
 
  185         index_t term, fac4=dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
 
  186                                  indices[0] =  iGlob         / fac0;
 
  187         term  = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
 
  188         term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
 
  189         term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
 
  190         term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
 
  191         term += indices[4]*fac4; indices[5] =  iGlob - term;
 
  192       } 
else if constexpr (N == 7) {
 
  193         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];
 
  194                                  indices[0] =  iGlob         / fac0;
 
  195         term  = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
 
  196         term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
 
  197         term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
 
  198         term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
 
  199         term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
 
  200         term += indices[5]*fac5; indices[6] =  iGlob - term;
 
  201       } 
else if constexpr (N == 8) {
 
  202         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];
 
  203                                  indices[0] =  iGlob         / fac0;
 
  204         term  = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
 
  205         term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
 
  206         term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
 
  207         term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
 
  208         term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
 
  209         term += indices[5]*fac5; indices[6] = (iGlob - term) / fac6;
 
  210         term += indices[6]*fac6; indices[7] =  iGlob - term;
 
  252       if constexpr (N >= 1) { lbounds[0] = b0.
l;   strides[0] =  b0.
s;   dims[0] = ( b0.
u - b0.
l + 1 ) / b0.
s; }
 
  253       if constexpr (N >= 2) { lbounds[1] = b1.l;   strides[1] =  b1.s;   dims[1] = ( b1.u - b1.l + 1 ) / b1.s; }
 
  254       if constexpr (N >= 3) { lbounds[2] = b2.l;   strides[2] =  b2.s;   dims[2] = ( b2.u - b2.l + 1 ) / b2.s; }
 
  255       if constexpr (N >= 4) { lbounds[3] = b3.l;   strides[3] =  b3.s;   dims[3] = ( b3.u - b3.l + 1 ) / b3.s; }
 
  256       if constexpr (N >= 5) { lbounds[4] = b4.l;   strides[4] =  b4.s;   dims[4] = ( b4.u - b4.l + 1 ) / b4.s; }
 
  257       if constexpr (N >= 6) { lbounds[5] = b5.l;   strides[5] =  b5.s;   dims[5] = ( b5.u - b5.l + 1 ) / b5.s; }
 
  258       if constexpr (N >= 7) { lbounds[6] = b6.l;   strides[6] =  b6.s;   dims[6] = ( b6.u - b6.l + 1 ) / b6.s; }
 
  259       if constexpr (N >= 8) { lbounds[7] = b7.l;   strides[7] =  b7.s;   dims[7] = ( b7.u - b7.l + 1 ) / b7.s; }
 
  261         if (N >= 2) { 
if (! b1.valid()) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  262         if (N >= 3) { 
if (! b2.valid()) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  263         if (N >= 4) { 
if (! b3.valid()) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  264         if (N >= 5) { 
if (! b4.valid()) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  265         if (N >= 6) { 
if (! b5.valid()) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  266         if (N >= 7) { 
if (! b6.valid()) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  267         if (N >= 8) { 
if (! b7.valid()) 
yakl_throw(
"ERROR: Too few bounds specified"); }
 
  269         if (b1.valid()) num_bounds++;
 
  270         if (b2.valid()) num_bounds++;
 
  271         if (b3.valid()) num_bounds++;
 
  272         if (b4.valid()) num_bounds++;
 
  273         if (b5.valid()) num_bounds++;
 
  274         if (b6.valid()) num_bounds++;
 
  275         if (b7.valid()) num_bounds++;
 
  276         if (num_bounds != N) 
yakl_throw(
"ERROR: Number of bounds passed does not match templated number of bounds.");
 
  279       for (
int i=0; i<N; i++) { nIter *= dims[i]; }
 
  284         if (i < 0 || i > N-1) 
yakl_throw(
"ERROR: Calling lbound() on an out of bounds integer");
 
  291         if (i < 0 || i > N-1) 
yakl_throw(
"ERROR: Calling dim() on an out of bounds integer");
 
  298         if (i < 0 || i > N-1) 
yakl_throw(
"ERROR: Calling stride() on an out of bounds integer");
 
  305       if constexpr        (N == 1) {
 
  307       } 
else if constexpr (N == 2) {
 
  308         indices[0] = iGlob/dims[1];
 
  309         indices[1] = iGlob - dims[1]*indices[0];
 
  310       } 
else if constexpr (N == 3) {
 
  312                                 fac = dims[1]*dims[2]; indices[0] =  iGlob         / fac;
 
  313         term  = indices[0]*fac; fac =         dims[2]; indices[1] = (iGlob - term) / fac;
 
  314         term += indices[1]*fac;                        indices[2] =  iGlob - term;
 
  315       } 
else if constexpr (N == 4) {
 
  317                                 fac = dims[1]*dims[2]*dims[3]; indices[0] =  iGlob         / fac;
 
  318         term  = indices[0]*fac; fac =         dims[2]*dims[3]; indices[1] = (iGlob - term) / fac;
 
  319         term += indices[1]*fac; fac =                 dims[3]; indices[2] = (iGlob - term) / fac;
 
  320         term += indices[2]*fac;                                indices[3] =  iGlob - term;
 
  321       } 
else if constexpr (N == 5) {
 
  323                                 fac = dims[1]*dims[2]*dims[3]*dims[4]; indices[0] =  iGlob         / fac;
 
  324         term  = indices[0]*fac; fac =         dims[2]*dims[3]*dims[4]; indices[1] = (iGlob - term) / fac;
 
  325         term += indices[1]*fac; fac =                 dims[3]*dims[4]; indices[2] = (iGlob - term) / fac;
 
  326         term += indices[2]*fac; fac =                         dims[4]; indices[3] = (iGlob - term) / fac;
 
  327         term += indices[3]*fac;                                        indices[4] =  iGlob - term;
 
  328       } 
else if constexpr (N == 6) {
 
  329         index_t term, fac4=dims[5], fac3=fac4*dims[4], fac2=fac3*dims[3], fac1=fac2*dims[2], fac0=fac1*dims[1];
 
  330                                  indices[0] =  iGlob         / fac0;
 
  331         term  = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
 
  332         term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
 
  333         term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
 
  334         term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
 
  335         term += indices[4]*fac4; indices[5] =  iGlob - term;
 
  336       } 
else if constexpr (N == 7) {
 
  337         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];
 
  338                                  indices[0] =  iGlob         / fac0;
 
  339         term  = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
 
  340         term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
 
  341         term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
 
  342         term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
 
  343         term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
 
  344         term += indices[5]*fac5; indices[6] =  iGlob - term;
 
  345       } 
else if constexpr (N == 8) {
 
  346         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];
 
  347                                  indices[0] =  iGlob         / fac0;
 
  348         term  = indices[0]*fac0; indices[1] = (iGlob - term) / fac1;
 
  349         term += indices[1]*fac1; indices[2] = (iGlob - term) / fac2;
 
  350         term += indices[2]*fac2; indices[3] = (iGlob - term) / fac3;
 
  351         term += indices[3]*fac3; indices[4] = (iGlob - term) / fac4;
 
  352         term += indices[4]*fac4; indices[5] = (iGlob - term) / fac5;
 
  353         term += indices[5]*fac5; indices[6] = (iGlob - term) / fac6;
 
  354         term += indices[6]*fac6; indices[7] =  iGlob - term;
 
  358       if constexpr (N >= 1) indices[0] = indices[0]*strides[0] + lbounds[0];
 
  359       if constexpr (N >= 2) indices[1] = indices[1]*strides[1] + lbounds[1];
 
  360       if constexpr (N >= 3) indices[2] = indices[2]*strides[2] + lbounds[2];
 
  361       if constexpr (N >= 4) indices[3] = indices[3]*strides[3] + lbounds[3];
 
  362       if constexpr (N >= 5) indices[4] = indices[4]*strides[4] + lbounds[4];
 
  363       if constexpr (N >= 6) indices[5] = indices[5]*strides[5] + lbounds[5];
 
  364       if constexpr (N >= 7) indices[6] = indices[6]*strides[6] + lbounds[6];
 
  365       if constexpr (N >= 8) indices[7] = indices[7]*strides[7] + lbounds[7];