User`s guide
Guidelines for Working with MWArray Classes
Examples of Using set. T he following examples construct the 2-by-2 matrix
of the p revious exam p le using the
set method. The first example uses a
single index:
int[] dims = {2, 2};
MWNumericArray a =
MWNumericArray.newInstance(dims, MWClassID.DOUBLE,
MWComplexity.REAL);
int index = 0;
double[] values = {1.0, 3.0, 2.0, 4.0};
for (int index = 1; index <= 4; index++)
a.set(index, values[index-1]);
Here is the same exam ple, but this tim e using an index array:
int[] dims = {2, 2};
MWNumericArray a =
MWNumericArray.newInstance(dims, MWClassID.DOUBLE,
MWComplexity.REAL);
int[] index = new int[2];
int k = 0;
for (index[0] = 1; index[0] <= 2; index[0]++)
{
for (index[1] = 1; index[1] <= 2; index[1]++)
a.set(index, ++k);
}
The sparse array example can likewise be rewritten using set as follows:
MWNumericArray a =
MWNumericArray.newSparse(4, 4, 10, MWClassID.DOUBLE,
MWComplexity.REAL);
int[] index = {1, 1};
for (index[0] = 1; index[0] <= 4; index[0]++)
{
for (index[1] = 1; index[1] <= 4; index[1]++)
{
if (index[1] == index[0])
4-19