Next: , Previous: Indirection position list, Up: Indirection


6.2 Cartesian-product indirection

The Cartesian product of the sets I, J and K is the set of (i,j,k) tuples for which i is in I, j is in J, and k is in K.

Blitz++ implements cartesian-product indirection using an adaptor which takes a set of STL containers and iterates through their Cartesian product. Note that the cartesian product is never explicitly created. You create the Cartesian-product adaptor by calling the function:

     template<class T_container>
     indexSet(T_container& c1, T_container& c2, ...)

The returned adaptor can then be used in the [] operator of an array object.

Here is a two-dimensional example:

       Array<int,2> A(6,6), B(6,6);
       A = 0;
       B = 10*tensor::i + tensor::j;
     
       vector<int> I, J;
       I.push_back(1);
       I.push_back(2);
       I.push_back(4);
     
       J.push_back(0);
       J.push_back(2);
       J.push_back(5);
     
       A[indexSet(I,J)] = B;

After this code, the A array contains:

      0   0   0   0   0   0
     10   0  12   0   0  15
     20   0  22   0   0  25
      0   0   0   0   0   0
     40   0  42   0   0  45
      0   0   0   0   0   0

All the containers used in a cartesian product must be the same type (e.g. all vector<int> or all set<TinyVector<int,2> >), but they may be different sizes. Singleton containers (containers containing a single value) are fine.