Java Reference
In-Depth Information
Matrix(int nrows, int ncols)
{
matrix = new double[nrows][ncols];
}
int getCols()
{
return matrix[0].length;
}
int getRows()
{
return matrix.length;
}
double getValue(int row, int col)
{
return matrix[row][col];
}
void setValue(int row, int col, double value)
{
matrix[row][col] = value;
}
}
Listing 6-8 demonstrates the single-threaded approach to multiplying two Matrix
instances:
Listing 6-8. Multiplying two Matrix instances via the standard matrix-multiplication algorithm
class MatMult
{
public static void main(String[] args)
{
Matrix a = new Matrix(1, 3);
a.setValue(0, 0, 1); // | 1 2 3 |
a.setValue(0, 1, 2);
a.setValue(0, 2, 3);
dump(a);
Matrix b = new Matrix(3, 2);
 
Search WWH ::




Custom Search