Array2DRowRealMatrix extends AbstractRealMatrix implements Serializable { @Override public void setSubMatrix(final double[][] subMatrix, final int row, final int column) throws NoDataException, OutOfRangeException, DimensionMismatchException, NullArgumentException { if (data == null) { if (row > 0) { throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row); } if (column > 0) { throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column); } MathUtils.checkNotNull(subMatrix); final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } data = new double[subMatrix.length][nCols]; for (int i = 0; i < data.length; ++i) { if (subMatrix[i].length != nCols) { throw new DimensionMismatchException(subMatrix[i].length, nCols); } System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols); } } else { super.setSubMatrix(subMatrix, row, column); } } 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 testSetSubMatrix() { Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData); m.setSubMatrix(detData2,1,1); RealMatrix expected = MatrixUtils.createRealMatrix (new double[][] {{1.0,2.0,3.0},{2.0,1.0,3.0},{1.0,2.0,4.0}}); Assert.assertEquals(expected, m); m.setSubMatrix(detData2,0,0); expected = MatrixUtils.createRealMatrix (new double[][] {{1.0,3.0,3.0},{2.0,4.0,3.0},{1.0,2.0,4.0}}); Assert.assertEquals(expected, m); m.setSubMatrix(testDataPlus2,0,0); expected = MatrixUtils.createRealMatrix (new double[][] {{3.0,4.0,5.0},{4.0,7.0,5.0},{3.0,2.0,10.0}}); Assert.assertEquals(expected, m); try { m.setSubMatrix(testData,1,1); Assert.fail("expecting OutOfRangeException"); } catch (OutOfRangeException e) { } try { m.setSubMatrix(testData,-1,1); Assert.fail("expecting OutOfRangeException"); } catch (OutOfRangeException e) { } try { m.setSubMatrix(testData,1,-1); Assert.fail("expecting OutOfRangeException"); } catch (OutOfRangeException e) { } try { m.setSubMatrix(null,1,1); Assert.fail("expecting NullArgumentException"); } catch (NullArgumentException e) { } Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(); try { m2.setSubMatrix(testData,0,1); Assert.fail("expecting MathIllegalStateException"); } catch (MathIllegalStateException e) { } try { m2.setSubMatrix(testData,1,0); Assert.fail("expecting MathIllegalStateException"); } catch (MathIllegalStateException e) { } try { m.setSubMatrix(new double[][] {{1}, {2, 3}}, 0, 0); Assert.fail("expecting MathIllegalArgumentException"); } catch (MathIllegalArgumentException e) { } try { m.setSubMatrix(new double[][] {{}}, 0, 0); Assert.fail("expecting MathIllegalArgumentException"); } catch (MathIllegalArgumentException e) { } }