def estimate_rank(data, tol='auto', return_singular=False, norm=True):
 data = data.copy()
 if (norm is True):
  norms = _compute_row_norms(data)
  data /= norms[:, np.newaxis]
 s = linalg.svd(data, compute_uv=False, overwrite_a=True)
 if isinstance(tol, string_types):
  if (tol != 'auto'):
   raise ValueError('tol must be "auto" or float')
  eps = np.finfo(float).eps
  tol = ((np.max(data.shape) * np.amax(s)) * eps)
 tol = float(tol)
 rank = np.sum((s > tol))
 if (return_singular is True):
  return (rank, s)
 else:
  return rank

def estimate_rank ( data , tol = 'auto' , return_singular = False , norm = True ) : data = data . copy ( ) if ( norm is True ) : norms = _compute_row_norms ( data ) data /= norms [ : , np . newaxis ] s = linalg . svd ( data , compute_uv = False , overwrite_a = True ) if isinstance ( tol , string_types ) : if ( tol != 'auto' ) : raise ValueError ( 'tol must be "auto" or float' ) eps = np . finfo ( float ) . eps tol = ( ( np . max ( data . shape ) * np . amax ( s ) ) * eps ) tol = float ( tol ) rank = np . sum ( ( s > tol ) ) if ( return_singular is True ) : return ( rank , s ) else : return rank
estimate matrix rank to a specified relative precision using randomized methods .