| 1 |
#include <blitz/array.h> |
| 2 |
|
| 3 |
using namespace blitz; |
| 4 |
|
| 5 |
int main() |
| 6 |
{ |
| 7 |
// 3x3 C-style row major storage, base zero |
| 8 |
Array<int,2> A(3, 3); |
| 9 |
|
| 10 |
// 3x3 column major storage, base zero |
| 11 |
Array<int,2> B(3, 3, ColumnMajorArray<2>()); |
| 12 |
|
| 13 |
// A custom storage format: |
| 14 |
// Indices have range 0..3, 0..3 |
| 15 |
// Column major ordering |
| 16 |
// Rows are stored ascending, columns stored descending |
| 17 |
GeneralArrayStorage<2> storage; |
| 18 |
storage.ordering() = firstRank, secondRank; |
| 19 |
storage.base() = 0, 0; |
| 20 |
storage.ascendingFlag() = true, false; |
| 21 |
|
| 22 |
Array<int,2> C(3, 3, storage); |
| 23 |
|
| 24 |
// Set each array equal to |
| 25 |
// [ 1 2 3 ] |
| 26 |
// [ 4 5 6 ] |
| 27 |
// [ 7 8 9 ] |
| 28 |
|
| 29 |
A = 1, 2, 3, |
| 30 |
4, 5, 6, |
| 31 |
7, 8, 9; |
| 32 |
|
| 33 |
cout << "A = " << A << endl; |
| 34 |
|
| 35 |
// Comma-delimited lists initialize in memory-storage order only. |
| 36 |
// Hence we list the values in column-major order to initialize B: |
| 37 |
|
| 38 |
B = 1, 4, 7, 2, 5, 8, 3, 6, 9; |
| 39 |
|
| 40 |
cout << "B = " << B << endl; |
| 41 |
|
| 42 |
// Array C is stored in column major, plus the columns are stored |
| 43 |
// in descending order! |
| 44 |
|
| 45 |
C = 3, 6, 9, 2, 5, 8, 1, 4, 7; |
| 46 |
|
| 47 |
cout << "C = " << C << endl; |
| 48 |
|
| 49 |
Array<int,2> D(3,3); |
| 50 |
D = A + B + C; |
| 51 |
|
| 52 |
#ifdef BZ_DEBUG |
| 53 |
A.dumpStructureInformation(); |
| 54 |
B.dumpStructureInformation(); |
| 55 |
C.dumpStructureInformation(); |
| 56 |
D.dumpStructureInformation(); |
| 57 |
#endif |
| 58 |
|
| 59 |
cout << "D = " << D << endl; |
| 60 |
|
| 61 |
return 0; |
| 62 |
} |
| 63 |
|