DiagonalMatrix extends AbstractRealMatrix implements Serializable { @Override public double[][] getData() { final int dim = getRowDimension(); final double[][] out = new double[dim][dim]; for (int i = 0; i < dim; i++) { out[i][i] = data[i]; } return out; } DiagonalMatrix(final int dimension);  DiagonalMatrix(final double[] d);  DiagonalMatrix(final double[] d, final boolean copyArray); @Override RealMatrix createMatrix(final int rowDimension,
                                   final int columnDimension); @Override RealMatrix copy(); DiagonalMatrix add(final DiagonalMatrix m); DiagonalMatrix subtract(final DiagonalMatrix m); DiagonalMatrix multiply(final DiagonalMatrix m); @Override RealMatrix multiply(final RealMatrix m); @Override double[][] getData(); double[] getDataRef(); @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 RealVector preMultiply(final RealVector v); DiagonalMatrix inverse(); DiagonalMatrix inverse(double threshold); boolean isSingular(double threshold);  }
@Test public void testGetData() { final double[] data = { -1.2, 3.4, 5 }; final int dim = 3; final DiagonalMatrix m = new DiagonalMatrix(dim); for (int i = 0; i < dim; i++) { m.setEntry(i, i, data[i]); } final double[][] out = m.getData(); Assert.assertEquals(dim, out.length); for (int i = 0; i < m.getRowDimension(); i++) { Assert.assertEquals(dim, out[i].length); for (int j = 0; j < m.getRowDimension(); j++) { if (i == j) { Assert.assertEquals(data[i], out[i][j], 0d); } else { Assert.assertEquals(0d, out[i][j], 0d); } } } }