Matrix implements Cloneable { public static Matrix diagonal(final double[] d) { Matrix M = new Matrix(d.length, d.length); for (int i = 0, j = 0; i < d.length; ++i, j += d.length + 1) { M.data_[j] = d[i]; } return M; } Matrix(final double[] data, final int nrows, final int ncols);  Matrix(final int nrows, final int ncols);  Matrix(final SubMatrix sm); static Matrix diagonal(final double[] d); static Matrix diagonal(final IReadDataBlock d); static Matrix diff(int n, int lag, int d); static Matrix diff(int n, Polynomial D); static Matrix identity(final int n); static Matrix square(final int n); static Matrix select(SubMatrix m, boolean[] rsel, boolean[] csel); static Matrix select(SubMatrix m, int[] rsel, int[] csel); static Matrix selectRows(SubMatrix m, boolean[] rsel); static Matrix selectRows(SubMatrix m, int[] rsel); static Matrix selectColumns(SubMatrix m, boolean[] csel); static Matrix selectColumns(SubMatrix m, int[] csel); void add(final double r); void add(final int row, final int col, final double val); void add(final Matrix M); void chs(); void clean(double epsilon); void clear(); @Override Matrix clone(); DataBlock column(final int col); List<DataBlock> columnList(); DataBlockIterator columns(); void copyTo(final double[] buffer, final int start); DataBlock diagonal(); DataBlock subDiagonal(int pos); DataBlock skewDiagonal(int pos); double get(final int row, final int col); int getColumnsCount(); int getRowsCount(); double[] internalStorage(); boolean isZero(double eps); boolean isDiagonal(double eps); boolean isZero(); boolean isDiagonal(); boolean isSquare(); Matrix minus(final double r); Matrix minus(final Matrix Y); void mul(final double r); void mul(final int row, final int col, final double val); double nrm2(); Matrix plus(final double r); Matrix plus(final Matrix Y); void randomize(); void randomize(int seed); DataBlock row(final int row); List<DataBlock> rowList(); DataBlockIterator rows(); void set(double value); void set(final int row, final int col, final double value); void set(MatrixFunction fn); void set(MatrixRelativeFunction fn); void add(MatrixFunction fn); void add(MatrixRelativeFunction fn); double ssq(); void sub(final double r); void sub(final Matrix M); SubMatrix all(); @Deprecated SubMatrix subMatrix(); SubMatrix subMatrix(final int r0, final int r1, final int c0,
            final int c1); double sum(); Matrix times(final double r); Matrix times(final Matrix Y); double dot(Matrix m); static Matrix rsolve(SubMatrix S, SubMatrix B); static Matrix lsolve(SubMatrix S, SubMatrix B); void toLower(); void toUpper(); Matrix transpose(); void addAY(double a, Matrix Y); void addXaXt(double a, DataBlock x); void addXaYt(double a, DataBlock x, DataBlock y); boolean isEmpty(); @Override String toString(); String toString(String fmt); @Override boolean equals(Object obj); boolean equals(Matrix other); boolean equals(Matrix other, double eps); @Override int hashCode(); int rank(); void permuteColumns(final int i, final int j); void permuteRows(final int i, final int j); void copy(Matrix C); double distance(Matrix m); void smooth(double eps); SubMatrix topLeft(); SubMatrix topLeft(int nr, int nc); SubMatrix bottomRight(); SubMatrix bottomRight(int nr, int nc);  }
@Test public void testDiagonal() { Matrix D = Matrix.square(20); D.diagonal().randomize(); assertTrue(D.isDiagonal()); assertTrue(D.isDiagonal(.001)); D.set(18, 19, .001); assertTrue(!D.isDiagonal()); assertTrue(D.isDiagonal(.001)); assertTrue(!D.isDiagonal(.000999)); }