@Test(
groups = "Functional",
- expectedExceptions = { IllegalArgumentException.class })
+ expectedExceptions =
+ { IllegalArgumentException.class })
public void testPreMultiply_tooManyColumns()
{
Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
@Test(
groups = "Functional",
- expectedExceptions = { IllegalArgumentException.class })
+ expectedExceptions =
+ { IllegalArgumentException.class })
public void testPreMultiply_tooFewColumns()
{
Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
m1.preMultiply(m1);
fail("Expected exception");
}
-
-
- private boolean matrixEquals(Matrix m1, Matrix m2) {
+
+ private boolean matrixEquals(Matrix m1, Matrix m2)
+ {
if (m1.width() != m2.width() || m1.height() != m2.height())
{
return false;
* (5040 50400)
*/
MatrixI m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } });
- MatrixI m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } });
+ MatrixI m2 = new Matrix(
+ new double[][]
+ { { 10, 100 }, { 1000, 10000 } });
MatrixI m3 = m1.postMultiply(m2);
assertEquals(Arrays.toString(m3.getRow(0)), "[3020.0, 30200.0]");
assertEquals(Arrays.toString(m3.getRow(1)), "[5040.0, 50400.0]");
{
int n = Integer.parseInt(args[0]);
double[][] in = new double[n][n];
-
+
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
in[i][j] = Math.random();
}
}
-
+
Matrix origmat = new Matrix(in);
-
+
// System.out.println(" --- Original matrix ---- ");
// / origmat.print(System.out);
// System.out.println();
// System.out.println(" --- transpose matrix ---- ");
MatrixI trans = origmat.transpose();
-
+
// trans.print(System.out);
// System.out.println();
// System.out.println(" --- OrigT * Orig ---- ");
MatrixI symm = trans.postMultiply(origmat);
-
+
// symm.print(System.out);
// System.out.println();
// Copy the symmetric matrix for later
// Matrix origsymm = symm.copy();
-
+
// This produces the tridiagonal transformation matrix
// long tstart = System.currentTimeMillis();
symm.tred();
-
+
// long tend = System.currentTimeMillis();
-
+
// System.out.println("Time take for tred = " + (tend-tstart) + "ms");
// System.out.println(" ---Tridiag transform matrix ---");
// symm.print(System.out);
// tstart = System.currentTimeMillis();
symm.tqli();
// tend = System.currentTimeMillis();
-
+
// System.out.println("Time take for tqli = " + (tend-tstart) + " ms");
// System.out.println(" --- New diagonalization matrix ---");
// symm.print(System.out);
}
}
return d;
-
+
}
/**
int rows = 10;
int cols = rows;
double[][] d = getSparseValues(rows, cols, 3);
-
+
/*
* make a copy of the values so m1, m2 are not
* sharing arrays!
* normal case
*/
double[][] vals = new double[2][];
- vals[0] = new double[] {7d, 1d, -2.3d};
- vals[1] = new double[] {-12d, 94.3d, -102.34d};
+ vals[0] = new double[] { 7d, 1d, -2.3d };
+ vals[1] = new double[] { -12d, 94.3d, -102.34d };
m = new Matrix(vals);
double[] minMax = m.findMinMax();
assertEquals(minMax[0], -102.34d);
public void testReverseRange_maxToZero()
{
Matrix m1 = new Matrix(
- new double[][] { { 2, 3.5, 4 }, { -3.4, 4, 15 } });
+ new double[][]
+ { { 2, 3.5, 4 }, { -3.4, 4, 15 } });
/*
* subtract all from max: range -3.4 to 15 becomes 18.4 to 0
public void testReverseRange_swapMinMax()
{
Matrix m1 = new Matrix(
- new double[][] { { 2, 3.5, 4 }, { -3.4, 4, 15 } });
-
+ new double[][]
+ { { 2, 3.5, 4 }, { -3.4, 4, 15 } });
+
/*
* swap all values in min-max range
* = subtract from (min + max = 11.6)
assertEquals(m1.getValue(1, 0), 15d, DELTA);
assertEquals(m1.getValue(1, 1), 7.6d, DELTA);
assertEquals(m1.getValue(1, 2), -3.4d, DELTA);
-
+
/*
* repeat operation - original values restored
*/
@Test(groups = "Functional")
public void testMultiply()
{
- Matrix m = new Matrix(new double[][] { { 2, 3.5, 4 }, { -3.4, 4, 15 } });
+ Matrix m = new Matrix(
+ new double[][]
+ { { 2, 3.5, 4 }, { -3.4, 4, 15 } });
m.multiply(2d);
assertEquals(m.getValue(0, 0), 4d, DELTA);
assertEquals(m.getValue(0, 1), 7d, DELTA);