Returns the matrix's rank. Automatic selection of threshold

@param A Matrix. Not modified.
@return The rank of the decomposed matrix.
320578
public static int rank( DMatrixRMaj A  ) {
        SingularValueDecomposition_F64<DMatrixRMaj> svd = DecompositionFactory_DDRM.svd(A.numRows,A.numCols,false,true,true);

        if( svd.inputModified() ) {
            A = A.copy();
        }
        if( !svd.decompose(A)) {
            throw new RuntimeException("SVD Failed!");
        }

        int N = svd.numberOfSingularValues();
        double sv[] = svd.getSingularValues();

        double threshold = singularThreshold(sv,N);
        int count = 0;
        for (int i = 0; i < sv.length; i++) {
            if( sv[i] >= threshold ) {
                count++;
            }
        }
        return count;
    }
202494
public static void divide( DMatrix5x5 a , double alpha ) {
        a.a11 /= alpha; a.a12 /= alpha; a.a13 /= alpha; a.a14 /= alpha; a.a15 /= alpha;
        a.a21 /= alpha; a.a22 /= alpha; a.a23 /= alpha; a.a24 /= alpha; a.a25 /= alpha;
        a.a31 /= alpha; a.a32 /= alpha; a.a33 /= alpha; a.a34 /= alpha; a.a35 /= alpha;
        a.a41 /= alpha; a.a42 /= alpha; a.a43 /= alpha; a.a44 /= alpha; a.a45 /= alpha;
        a.a51 /= alpha; a.a52 /= alpha; a.a53 /= alpha; a.a54 /= alpha; a.a55 /= alpha;
    }
612135
public static DMatrixSparseCSC extractColumn(DMatrixSparseCSC A , int column , @Nullable DMatrixSparseCSC out ) {

        if( out == null )
            out = new DMatrixSparseCSC(1,1,1);

        int idx0 = A.col_idx[column];
        int idx1 = A.col_idx[column+1];

        out.reshape(A.numRows,1,idx1-idx0);
        out.nz_length = idx1-idx0;

        out.col_idx[0] = 0;
        out.col_idx[1] = out.nz_length;

        System.arraycopy(A.nz_values,idx0,out.nz_values,0,out.nz_length);
        System.arraycopy(A.nz_rows,idx0,out.nz_rows,0,out.nz_length);

        return out;
    }
324384
public static double elementMax( DMatrix5 a ) {
        double max = a.a1;
        if( a.a2 > max ) max = a.a2;
        if( a.a3 > max ) max = a.a3;
        if( a.a4 > max ) max = a.a4;
        if( a.a5 > max ) max = a.a5;

        return max;
    }
116888
public static void symmRankTranA_sub(DMatrixRMaj a , DMatrixRMaj c ,
                                         int startIndexC )
    {
        // TODO update so that it doesn't modify/read parts that it shouldn't
        final double dataA[] = a.data;
        final double dataC[] = c.data;

//        for( int i = 0; i < a.numCols; i++ ) {
//            for( int k = 0; k < a.numRows; k++ ) {
//                double valA = dataA[k*a.numCols+i];
//
//                for( int j = i; j < a.numCols; j++ ) {
//                    dataC[startIndexC+i*c.numCols+j] -= valA * dataA[k*a.numCols+j];
//                }
//            }
//        }

        final int strideC = c.numCols + 1;
        for( int i = 0; i < a.numCols; i++ ) {
            int indexA = i;
            int endR = a.numCols;

            for( int k = 0; k < a.numRows; k++ , indexA += a.numCols , endR += a.numCols) {
                int indexC = startIndexC;
                final double valA = dataA[indexA];
                int indexR = indexA;

                while( indexR < endR ) {
                    dataC[indexC++] -= valA * dataA[indexR++];
                }
            }
            startIndexC += strideC;
        }

    }
1123424
@Override
    public boolean decompose(DMatrixRBlock A) {
        if( A.numCols != A.numRows )
            throw new IllegalArgumentException("A must be square");

        this.T = A;

        if( lower )
            return decomposeLower();
        else
            return decomposeUpper();
    }
248360
public static double getValueForRank(int rank,double[] scores){
    double[] copy = new double[scores.length];
    System.arraycopy(scores,0,copy,0,scores.length);
    java.util.Arrays.sort(copy);
    rank = scores.length-rank;
    return copy[rank];
  }
187326
def sort_matrix(a,n=0):
    
    a = _n.array(a)
    return a[:,a[n,:].argsort()]
778839
public static void divide( DMatrix3 a , double alpha ) {
        a.a1 /= alpha;
        a.a2 /= alpha;
        a.a3 /= alpha;
    }
340962
protected void convertToColumnMajor(ZMatrixRMaj A) {
        for( int x = 0; x < numCols; x++ ) {
            double colQ[] = dataQR[x];
            int indexCol = 0;
            for( int y = 0; y < numRows; y++ ) {
                int index = (y*numCols+x)*2;
                colQ[indexCol++] = A.data[index];
                colQ[indexCol++] = A.data[index+1];
            }
        }
    }
657594
private static int[] findDiagonalIndices(CompRowMatrix A) {
            int[] rowptr = A.getRowPointers();
            int[] colind = A.getColumnIndices();

            int[] diagIndices = new int[A.numRows()];

            for (int i = 0; i < A.numRows(); ++i) {
                diagIndices[i] = no.uib.cipr.matrix.sparse.Arrays.binarySearch(
                        colind, i, rowptr[i], rowptr[i + 1]);
                if (diagIndices[i] < 0)
                    throw new RuntimeException(
                            "Matrix is missing a diagonal entry on row "
                                    + (i + 1));
            }

            return diagIndices;
        }
1005103
public SymmDenseEVD factor(LowerSymmDenseMatrix A)
            throws NotConvergedException {
        if (uplo != UpLo.Lower)
            throw new IllegalArgumentException(
                    "Eigenvalue computer configured for lower-symmetrical matrices");

        return factor(A, A.getData());
    }
206597
function rank(A, tol) {
    var S = svd(A, false, false)[0];
    if (tol === undefined) {
        tol = common_1.EPSILON; // TODO : use numpy's formula
    }
    var rank = 0;
    for (var _i = 0, _a = S.toArray(); _i < _a.length; _i++) {
        var n = _a[_i];
        if (n > tol) {
            rank++;
        }
    }
    return rank;
}
46134
@Override
    public DMatrixRMaj getQ(DMatrixRMaj Q , boolean compact ) {
        if( compact ) {
            Q = UtilDecompositons_DDRM.checkIdentity(Q,numRows,minLength);
        } else {
            Q = UtilDecompositons_DDRM.checkIdentity(Q,numRows,numRows);
        }

        for( int j = minLength-1; j >= 0; j-- ) {
            double u[] = dataQR[j];

            double vv = u[j];
            u[j] = 1;
            QrHelperFunctions_DDRM.rank1UpdateMultR(Q, u, gammas[j], j, j, numRows, v);
            u[j] = vv;
        }

        return Q;
    }
481166
public static double elementMin( DMatrix6 a ) {
        double min = a.a1;
        if( a.a2 < min ) min = a.a2;
        if( a.a3 < min ) min = a.a3;
        if( a.a4 < min ) min = a.a4;
        if( a.a5 < min ) min = a.a5;
        if( a.a6 < min ) min = a.a6;

        return min;
    }
444580
public static void sort(DenseMatrix64F matrix, RowComparator comparator)
    {
        int len = matrix.numCols;
        quickSort(matrix.data, 0, matrix.numRows-1, len, comparator, new double[len], new double[len]);
    }
938622
public double rcond(Matrix A) {
        if (n != A.numRows())
            throw new IllegalArgumentException("n != A.numRows()");
        if (!A.isSquare())
            throw new IllegalArgumentException("!A.isSquare()");

        double anorm = A.norm(Norm.One);

        double[] work = new double[3 * n];
        int[] iwork = new int[n];

        intW info = new intW(0);
        doubleW rcond = new doubleW(0);
        if (upper)
            LAPACK.getInstance().dpocon(UpLo.Upper.netlib(), n, Cu.getData(),
                    Matrices.ld(n), anorm, rcond, work, iwork, info);
        else
            LAPACK.getInstance().dpocon(UpLo.Lower.netlib(), n, Cl.getData(),
                    Matrices.ld(n), anorm, rcond, work, iwork, info);

        if (info.val < 0)
            throw new IllegalArgumentException();

        return rcond.val;
    }