Vectors and Matrices

DAPPLE provides two new classes of data: Vector and Matrix. You can define one- and two-dimensional data sets, and manipulate them with many of the usual C++ operators, in parallel. In addition, you can compute some functions of the entire vector or matrix, such as summing all the elements. Finally, you can move elements around, perhaps to sort them.


Vectors.

A vector is simply a one-dimensional collection of elements. Each element is a scalar value, and can be an integer, character, boolean, or single- or double-precision floating-point number. For example, a vector of N integers called "data" can be defined with intVector data(N); The elements in this vector are not initialized. Later, it should be initialized in an assignment statement. To initialize it when it is defined, so that all of the elements have the same value, you can include a second argument: intVector data(N, 3); Here, all N elements of vector "data" have the value 3. If you have an array that already contains some interesting data, you can initialize the vector from the contents of the array: const int N = 4; int array[N] = {45, 23, -3, 9}; intVector data(N, array); A final possibility is to initialize the elements to some function of their position in the vector. (The first element is at position 0, the next at position 1, and the last at position N-1.) int somefunc(const int position); intVector data(N, somefunc); Here, the first element of the new vector will be initialized to somefunc(0), and the last element will be initialized to somefunc(N-1). The predefined function called Identity() is useful for this purpose: Identity(i) returns i, so intVector data(N, Identity); initializes data to the set of values 0, 1, 2, ..., N-1.

There are other vector types, used the same way:

intVector A(N); charVector B(N); floatVector C(N); doubleVector D(N); booleanVector E(N);

Matrices.

Matrices are used much like vectors. For example, the following all define matrices with N rows and M columns: intMatrix A1(N,M, IdentityR); intMatrix A2(N,M, IdentityC); charMatrix B(N,M, 'x'); floatMatrix C(N,M); doubleMatrix D(N,M, data); booleanMatrix E(N,M, false); Integer matrix A1 is initialized so that every element's value is its row number; IdentityR(r,c) is a predefined function that returns r. Integer matrix A2 is initialized so that every element's value is its column number; IdentityC(r,c) is a predefined function that returns c. Thus, for matrices, the function initializer takes two parameters (the row and column) instead of one.

All elements in character matrix B are initialized to the character 'x'. Float matrix C is uninitialized. Double matrix D is initialized from a two-dimensional array called data, which should have the dimensions [N][M]. Finally, all elements in boolean matrix E are initialized to false.