Class CAMdoubleArray Reference

Include File :cammva.h


A class for arrays of values of type double. Arrays may be from dimension one to seven.

 The class CAMmvaGraphics provides graphical output routines that accept CAMdoubleArray arguments. Specific functions for CAMdoubleArray are described in "Graphics Functions for CAMdoubleArray"

Chris Anderson © UCLA 8/18/97


Constructors

CAMdoubleArray A(m1, m2, …); An array A of size m1 by m2 by … with the indexing starting at 1. The dimension of the array is determined from the number of input arguments and may be from 1 to 7.
CAMdoubleArray A(_(m1, n1), _(m2,n2), ...); An array with a first index running from m1 to n1, a second index running from m2 to n2 etc.

_(m1,m2) and _(m2,n2) are CAMrange objects.
CAMdoubleArray A; An array A of 0 size (a null Array).
CAMdoubleArray A = T; An array A which is a copy of an array T.

Often, when programming with CAMdoubleArray objects one desires to change the structure of an existing object. The initialize function allows one to re-initialize an existing object to have a different structure. The initialization process discards any data previously associated with the object. The new data values are initialized to 0.

Initialize

A.initialize(); A is initialized to a null array.
A.initialize(m,n,…); A is initialized to an array of size m1 by m2 by … with the indexing starting at 1. The dimension of the array is determined from the number of input arguments and may be from 1 to 7.
A.initialize(_(m1,m2),_(n1,n2), ...); A is initialized to an array with a first index running from m1 to n1, a second index running from m2 to n2 etc.
_(m1,m2) and _(m2,n2) are CAMrange objects.
A.initialize(T); A is initialized as a copy of the array T.


Unary and Binary Operations

= Assignment. A = T; assigns to A the values in the array T.
+ Addition. A = T + S; assigns to A the sum T + S.
- Subtraction. A = T - S; assigns to A the difference T - S.
* Multiplication. A= S*T assigns the CAMdoubleArray A the product of the elements of CAMdoubleArray S with the elements of the CAMdoubleArray T. (Element by element multiplication).
/ A = S/T assigns to A the quotient of the elements of S and T. (Element by element division).
-() Negation. A = -T; assigns to A the opposite of the values in T.
+= Incremental addition. A+=T; is equivalent to A = A+ T;
-= Incremental subtraction . A-=T is equivalent to A = A - Y;
*= Incremental multiplication. A*=T is equivalent to A =A*T;
/= Incremental division. A/=T is equivalent to A =A/T;
<< Array output. cout << A; outputs the array to the output stream cout.
>> Array input. cin >> A; inputs the array from the input stream cin.

The operators in the table above are applicable whenever the expression in which they are contained makes mathematical sense, i.e. the dimensions and the type of the object are correct. 

Scaler multiplication and division of array objects is allowed (except in the case of a one element array, then the assignment, addition, or subtraction with a scaler using the operators -, +, and = results in an error. The member functions setToValue(), plusValue(), minusValue() are used for such operations.)


Array Element Access

A(i,j,..); The element of the array A whose index is (i,j,…).
A(r1, r2, …); The sub-array of A which is specified by having each r1, r2, etc. be single indices or CAMrange expressions (an _ or _(i1,i2)).

Each of the expressions in the previous table can occur on the left as well as the right hand side of an assignment statement. So, for example, the statement

A(1,_) = A(2,_) + A(4,_);

adds to all the elements associated with a first index value 1 the sum of the elements with first index value 2 and first index value 4.

There is one syntax construction in C++ which does not work when dealing with sub-arrays - ``multiple assignment'' statements of the form A = B = C. For example, the statement

A = B(_(2,3),_(2,3)) = C;

will cause the compiler to issue an error and stop. This is an artifact of our particular implementation of these classes.


Array Structure Access

n = A[i].getIndexCount(); n (a long) is assigned the number of elements associated with the ith dimension of A.
n = A[i].getIndexBase(); n (a long) is assigned the index starting value for the ith dimension of A.
n = A[i].getIndexBound(); n (a long) is assigned index starting value associated with the ith dimension of A.
A[i].setIndexBase(n); The starting index of the ith dimension of A is set to the long n
d = A.getDataPointer(); The pointer d (of type double*) is set to the address of the first element of the data in A. The data is stored by columns (FORTRAN storage convention).


Array Utility Functions

d = A.max(); A double d is assigned the maximum of the elements of the A.
d = A.min(); A double d is assigned the minimum of the elements of A.
d = A.maxAbs(); A double d is assigned the maximum of the absolute value of the elements of A.
d = A.minAbs(); A double d is assigned the minimum of the absolute value of the elements of CAMdoubleArray A.
A.setToValue(d); Every element of A is set to the value d.
R=A.plusValue(d); R is set to the array obtained by adding d to every element of A.
R=A.minusValue(d); R is set to the array obtained by subtracting d from every element of A.