MatlibMatrixUtils { public static Matrix dotProduct(Matrix X, Matrix W) { final Matrix ret = X.newInstance(X.rowCount(), W.columnCount()); for (int j = 0; j < ret.columnCount(); j++) { final Vector column = W.column(j); for (int i = 0; i < ret.rowCount(); i++) { ret.put(i, j, X.row(i).dot(column)); } } return ret; }  static double sparsity(Matrix mat); static T powInplace(T matrix, double d); static SparseMatrix times(DiagonalMatrix D, SparseMatrix A); static SparseMatrix times(SparseMatrix A, DiagonalMatrix D); static SparseMatrix plusInplace(SparseMatrix A, Matrix B); @SuppressWarnings("unchecked") static T plusInplace(T A, Matrix B); static T plusInplace(T A, double d); static T minusInplace(DiagonalMatrix D, T A); static Matrix minusInplace(Matrix A, Matrix B); static T minusInplace(T A, Vector D); static T plusInplace(T A, Vector D); static T plusInplace(DiagonalMatrix D, T A); static Matrix transposeDotProduct(Matrix A, Matrix B); static Matrix dotProductTranspose(Matrix A, Matrix B); static Matrix dotProductTransposeTranspose(Matrix A, Matrix B); static T dotProductTranspose(Matrix A, Matrix B,
			T Y); static T scaleInplace(T A, double s); static Jama.Matrix toJama(Matrix laplacian); static Jama.Matrix toColJama(Vector vector); static Jama.Matrix toRowJama(Vector vector); static Matrix fromJama(Jama.Matrix sol); static no.uib.cipr.matrix.Matrix toMTJ(Matrix sol); static T subMatrix(T mat, int rowstart,
			int rowend, int colstart, int colend); static T subMatrix(final T mat,
			TIntCollection rows, TIntCollection cols); static T subMatrix(final T mat,
			TIntArrayList rows, final int colstart, final int colend); static T subMatrix(final T mat,
			final int rowstart, final int rowend, TIntArrayList cols); static MLDouble asMatlab(Matrix m); static double[] minmaxmean(Matrix mat); static double min(Matrix mat); static double max(Matrix mat); static double mean(Matrix mat); static T minus(T l, double v); static Vector minus(Vector l, Vector v); static T minus(double v, T l); static Matrix fromMatlab(MLArray mlArray); static double sum(DiagonalMatrix d); static void setSubMatrix(Matrix to, int row, int col, Matrix from); static T transpose(T mat); static SparseMatrix maxInplace(SparseMatrix A, SparseMatrix B); static SparseMatrix minInplace(SparseMatrix A, SparseMatrix B); static SparseMatrix timesInplace(SparseMatrix A, SparseMatrix B); static Matrix timesInplace(Matrix A, Matrix B); static T copy(T sparseMatrix); static SparseMatrix threshold(SparseMatrix data, double thresh); static SparseDoubleArray sparseVectorToSparseArray(
			ch.akuhn.matrix.SparseVector row); static void setSubVector(Vector to, int startindex, Vector from); static void setSubMatrixRow(Matrix to, int row, int col, Vector v); static void setSubMatrixCol(Matrix to, int row, int col, Vector v); static Vector lessThan(Vector v, double d); static boolean any(Vector v); static T appendColumn(T m, Vector col); static T appendRow(T m, Vector row); static Matrix fromCF(gov.sandia.cognition.math.matrix.Matrix init); static Matrix dotProduct(Matrix X, Matrix W); static double norm2(Vector row); static Matrix minus(Matrix A, Matrix B); static double normF(Matrix A); static Matrix vstack(Matrix... matricies);  }
@Test public void testDotProduct() throws Exception { final Matrix X = new DenseMatrix(new double[][] { { 1, 1, }, { 2, 2, }, }); final Matrix expected = new DenseMatrix(new double[][] { { 3, 3, }, { 6, 6, }, }); final Matrix m = MatlibMatrixUtils.dotProduct(X, X); final double[][] asArray = MatlibMatrixUtils.minusInplace(m, expected).asArray(); assertTrue(new no.uib.cipr.matrix.DenseMatrix(asArray).norm(Norm.Frobenius) == 0); }