import java.io.PrintStream;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * A class to model rectangular matrices of double values and operations on them
*/
-public class Matrix
+public class Matrix implements MatrixI
{
/*
- * the [row][column] values in the matrix
+ * the cell values in row-major order
*/
- public double[][] value;
+ private double[][] value;
/*
* the number of rows
/*
* the number of columns
*/
- public int cols;
+ protected int cols;
-- /** DOCUMENT ME!! */
- public double[] d; // Diagonal
+ protected double[] d; // Diagonal
-- /** DOCUMENT ME!! */
- public double[] e; // off diagonal
+ protected double[] e; // off diagonal
/**
* maximum number of iterations for tqli
for (k = 1; k <= l; k++)
{
- double x = addValue(k - 1, j - 1, -(g * getValue(k - 1, i - 1)));
- value[k - 1][j - 1] -= (g * value[k - 1][i - 1]);
++ addValue(k - 1, j - 1, -(g * getValue(k - 1, i - 1)));
}
}
}
* and check premultiply equivalent
*/
m3 = m2.preMultiply(m1);
- assertEquals(m3.rows, 1);
- assertEquals(m3.cols, 2);
- assertEquals(m3.value[0][0], 56d);
- assertEquals(m3.value[0][1], 25d);
+ assertEquals(m3.height(), 1);
+ assertEquals(m3.width(), 2);
+ assertEquals(m3.getRow(0)[0], 56d);
+ assertEquals(m3.getRow(0)[1], 25d);
}
+ @Test(groups = "Functional")
+ public void testCopy()
+ {
+ Random r = new Random();
+ int rows = 5;
+ int cols = 11;
+ double[][] in = new double[rows][cols];
+
+ for (int i = 0; i < rows; i++)
+ {
+ for (int j = 0; j < cols; j++)
+ {
+ in[i][j] = r.nextDouble();
+ }
+ }
+ Matrix m1 = new Matrix(in);
- Matrix m2 = m1.copy();
++ Matrix m2 = (Matrix) m1.copy();
+ assertTrue(matrixEquals(m1, m2));
+ }
+
/**
* main method extracted from Matrix
*