RRQRDecomposition extends QRDecomposition { public int getRank(final double dropThreshold) { RealMatrix r = getR(); int rows = r.getRowDimension(); int columns = r.getColumnDimension(); int rank = 1; double lastNorm = r.getFrobeniusNorm(); double rNorm = lastNorm; while (rank < FastMath.min(rows, columns)) { double thisNorm = r.getSubMatrix(rank, rows - 1, rank, columns - 1).getFrobeniusNorm(); if (thisNorm == 0 || (thisNorm / lastNorm) * rNorm < dropThreshold) { break; } lastNorm = thisNorm; rank++; } return rank; } RRQRDecomposition(RealMatrix matrix);  RRQRDecomposition(RealMatrix matrix,  double threshold); RealMatrix getP(); int getRank(final double dropThreshold); @Override DecompositionSolver getSolver();  }
@Test public void testRank() { double[][] d = { { 1, 1, 1 }, { 0, 0, 0 }, { 1, 2, 3 } }; RealMatrix m = new Array2DRowRealMatrix(d); RRQRDecomposition qr = new RRQRDecomposition(m); Assert.assertEquals(2, qr.getRank(1.0e-16)); }