Array2DRowRealMatrix extends AbstractRealMatrix implements Serializable { @Override public double[] preMultiply(final double[] v) throws DimensionMismatchException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nRows) { throw new DimensionMismatchException(v.length, nRows); } final double[] out = new double[nCols]; for (int col = 0; col < nCols; ++col) { double sum = 0; for (int i = 0; i < nRows; ++i) { sum += data[i][col] * v[i]; } out[col] = sum; } return out; } 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 testPremultiplyVector() { RealMatrix m = new Array2DRowRealMatrix(testData); TestUtils.assertEquals("premultiply", m.preMultiply(testVector), preMultTest, normTolerance); TestUtils.assertEquals("premultiply", m.preMultiply(new ArrayRealVector(testVector).toArray()), preMultTest, normTolerance); m = new Array2DRowRealMatrix(bigSingular); try { m.preMultiply(testVector); Assert.fail("expecting MathIllegalArgumentException"); } catch (MathIllegalArgumentException ex) { } }
@Test public void testPremultiply() { RealMatrix m3 = new Array2DRowRealMatrix(d3); RealMatrix m4 = new Array2DRowRealMatrix(d4); RealMatrix m5 = new Array2DRowRealMatrix(d5); TestUtils.assertEquals("m3*m4=m5", m4.preMultiply(m3), m5, entryTolerance); Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData); Array2DRowRealMatrix mInv = new Array2DRowRealMatrix(testDataInv); Array2DRowRealMatrix identity = new Array2DRowRealMatrix(id); TestUtils.assertEquals("inverse multiply",m.preMultiply(mInv), identity,entryTolerance); TestUtils.assertEquals("inverse multiply",mInv.preMultiply(m), identity,entryTolerance); TestUtils.assertEquals("identity multiply",m.preMultiply(identity), m,entryTolerance); TestUtils.assertEquals("identity multiply",identity.preMultiply(mInv), mInv,entryTolerance); try { m.preMultiply(new Array2DRowRealMatrix(bigSingular)); Assert.fail("Expecting illegalArgumentException"); } catch (MathIllegalArgumentException ex) { } }