![]() |
Blitz Devel : |
From: Todd Veldhuizen (tveldhui_at_[hidden])
Date: 1998-07-30 17:43:11
Here is a first pass at the design of indirection for Blitz++.
Comments please.
Indirection = the ability to modify an array at a set of
selected index values.
In the current design, an index set is contained in an STL
container (note: once stl iterators are provided for
Array, Vector etc. you will be able to use these for
indirection).
Example (one-dimensional array):
Array<int,1> A(5), B(5);
A = 0;
B = 0, 1, 2, 3, 4;
vector<int> I;
I.push_back(2);
I.push_back(4);
I.push_back(1);
A[I] = B;
B = [ 0 1 2 3 4 ]
A = [ 0 1 2 0 4 ]
For multidimensional arrays, you can have a container of
TinyVectors:
Array<int,2> A(4,4), B(4,4);
A = 0;
B = 10*tensor::i + tensor::j;
typedef TinyVector<int,2> coord;
list<coord> I;
I.push_back(coord(1,1));
I.push_back(coord(2,2));
A[I] = B;
B = 4 x 4
0 1 2 3
10 11 12 13
20 21 22 23
30 31 32 33
A = 4 x 4
0 0 0 0
0 11 0 0
0 0 22 0
0 0 0 0
You can also do cartesian products of index sets:
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(2);
J.push_back(0);
J.push_back(5);
A[indexSet(I,J)] = B;
The indexSet(I,J) returns an "adaptor" which allows
iteration through the cartesian product of I X J.
This will be provided for 3, 4-dimensions as well
(and higher if desired).
B = 6 x 6
0 1 2 3 4 5
10 11 12 13 14 15
20 21 22 23 24 25
30 31 32 33 34 35
40 41 42 43 44 45
50 51 52 53 54 55
A = 6 x 6
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
Question: does anyone have use for something like
indexSet which allows singletons too?
e.g. indexSet(I,2,K) = all <i,2,k> with i \in I and k \in K?
--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo_at_[hidden], with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/