@Test public void testTimesMatrix() { Matrix transpose = test.transpose(); Matrix value = test.times(transpose); assertEquals("rows", test.rowSize(), value.rowSize()); assertEquals("cols", test.rowSize(), value.columnSize()); Matrix expected = new DenseMatrix(new double[][]{{5.0, 11.0, 17.0}, {11.0, 25.0, 39.0}, {17.0, 39.0, 61.0}}).times(1.21); for (int i = 0; i < expected.numCols(); i++) { for (int j = 0; j < expected.numRows(); j++) { assertTrue("Matrix times transpose not correct: " + i + ", " + j + "\nexpected:\n\t" + expected + "\nactual:\n\t" + value, Math.abs(expected.get(i, j) - value.get(i, j)) < 1.0e-12); } } Matrix timestest = new DenseMatrix(10, 1); /* will throw ArrayIndexOutOfBoundsException exception without MAHOUT-26 */ timestest.transpose().times(timestest); }
@Test public void testTimesMatrix() { Matrix transpose = test.transpose(); Matrix value = test.times(transpose); assertEquals("rows", test.rowSize(), value.rowSize()); assertEquals("cols", test.rowSize(), value.columnSize()); Matrix expected = new DenseMatrix(new double[][]{{5.0, 11.0, 17.0}, {11.0, 25.0, 39.0}, {17.0, 39.0, 61.0}}).times(1.21); for (int i = 0; i < expected.numCols(); i++) { for (int j = 0; j < expected.numRows(); j++) { assertTrue("Matrix times transpose not correct: " + i + ", " + j + "\nexpected:\n\t" + expected + "\nactual:\n\t" + value, Math.abs(expected.get(i, j) - value.get(i, j)) < 1.0e-12); } } Matrix timestest = new DenseMatrix(10, 1); /* will throw ArrayIndexOutOfBoundsException exception without MAHOUT-26 */ timestest.transpose().times(timestest); }