Array2DRowRealMatrix extends AbstractRealMatrix implements Serializable { public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m) throws DimensionMismatchException { MatrixUtils.checkMultiplicationCompatible(this, m); final int nRows = this.getRowDimension(); final int nCols = m.getColumnDimension(); final int nSum = this.getColumnDimension(); final double[][] outData = new double[nRows][nCols]; final double[] mCol = new double[nSum]; final double[][] mData = m.data; for (int col = 0; col < nCols; col++) { for (int mRow = 0; mRow < nSum; mRow++) { mCol[mRow] = mData[mRow][col]; } for (int row = 0; row < nRows; row++) { final double[] dataRow = data[row]; double sum = 0; for (int i = 0; i < nSum; i++) { sum += dataRow[i] * mCol[i]; } outData[row][col] = sum; } } return new Array2DRowRealMatrix(outData, false); } Array2DRowRealMatrix();  Array2DRowRealMatrix(final int rowDimension,
                                final int columnDimension);  Array2DRowRealMatrix(final double[][] d);  Array2DRowRealMatrix(final double[][] d, final boolean copyArray);  Array2DRowRealMatrix(final double[] v); @Override RealMatrix createMatrix(final int rowDimension,
                                   final int columnDimension); @Override RealMatrix copy(); Array2DRowRealMatrix add(final Array2DRowRealMatrix m); Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m); Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m); @Override double[][] getData(); double[][] getDataRef(); @Override void setSubMatrix(final double[][] subMatrix, final int row,
                             final int column); @Override double getEntry(final int row, final int column); @Override void setEntry(final int row, final int column, final double value); @Override void addToEntry(final int row, final int column,
                           final double increment); @Override void multiplyEntry(final int row, final int column,
                              final double factor); @Override int getRowDimension(); @Override int getColumnDimension(); @Override double[] operate(final double[] v); @Override double[] preMultiply(final double[] v); @Override double walkInRowOrder(final RealMatrixChangingVisitor visitor); @Override double walkInRowOrder(final RealMatrixPreservingVisitor visitor); @Override double walkInRowOrder(final RealMatrixChangingVisitor visitor,
                                 final int startRow, final int endRow,
                                 final int startColumn, final int endColumn); @Override double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
                                 final int startRow, final int endRow,
                                 final int startColumn, final int endColumn); @Override double walkInColumnOrder(final RealMatrixChangingVisitor visitor); @Override double walkInColumnOrder(final RealMatrixPreservingVisitor visitor); @Override double walkInColumnOrder(final RealMatrixChangingVisitor visitor,
                                    final int startRow, final int endRow,
                                    final int startColumn, final int endColumn); @Override double walkInColumnOrder(final RealMatrixPreservingVisitor visitor,
                                    final int startRow, final int endRow,
                                    final int startColumn, final int endColumn);  }
@Test public void testMultiply() { Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData); Array2DRowRealMatrix mInv = new Array2DRowRealMatrix(testDataInv); Array2DRowRealMatrix identity = new Array2DRowRealMatrix(id); Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(testData2); TestUtils.assertEquals("inverse multiply",m.multiply(mInv), identity,entryTolerance); TestUtils.assertEquals("inverse multiply",mInv.multiply(m), identity,entryTolerance); TestUtils.assertEquals("identity multiply",m.multiply(identity), m,entryTolerance); TestUtils.assertEquals("identity multiply",identity.multiply(mInv), mInv,entryTolerance); TestUtils.assertEquals("identity multiply",m2.multiply(identity), m2,entryTolerance); try { m.multiply(new Array2DRowRealMatrix(bigSingular)); Assert.fail("Expecting illegalArgumentException"); } catch (MathIllegalArgumentException ex) { } }
@Test public void testMultiply2() { RealMatrix m3 = new Array2DRowRealMatrix(d3); RealMatrix m4 = new Array2DRowRealMatrix(d4); RealMatrix m5 = new Array2DRowRealMatrix(d5); TestUtils.assertEquals("m3*m4=m5", m3.multiply(m4), m5, entryTolerance); }