Parameters
    ----------
    n_pcs : `int` or `None`, optional (default: `None`)
        If `n_pcs=0`, do not preprocess with PCA.
        If `None` and there is a PCA version of the data, use this.
        If an integer, compute the PCA.
183600
def preprocess_with_pca(adata, n_pcs=None, random_state=0):
    
    if n_pcs == 0:
        logg.info('    using data matrix X directly (no PCA)')
        return adata.X
    elif n_pcs is None and 'X_pca' in adata.obsm_keys():
        logg.info('    using \'X_pca\' with n_pcs = {}'
                  .format(adata.obsm['X_pca'].shape[1]))
        return adata.obsm['X_pca']
    elif ('X_pca' in adata.obsm_keys()
          and adata.obsm['X_pca'].shape[1] >= n_pcs):
        logg.info('    using \'X_pca\' with n_pcs = {}'
                  .format(n_pcs))
        return adata.obsm['X_pca'][:, :n_pcs]
    else:
        n_pcs = N_PCS if n_pcs is None else n_pcs
        if adata.X.shape[1] > n_pcs:
            logg.info('    computing \'X_pca\' with n_pcs = {}'.format(n_pcs))
            logg.hint('avoid this by setting n_pcs = 0')
            X = pca(adata.X, n_comps=n_pcs, random_state=random_state)
            adata.obsm['X_pca'] = X
            return X
        else:
            logg.info('    using data matrix X directly (no PCA)')
            return adata.X
1012040
def choose(n, k):
    
    if 0 <= k <= n:
        ntok = 1
        ktok = 1
        for t in xrange(1, min(k, n - k) + 1):
            ntok *= n
            ktok *= t
            n -= 1
        return ntok // ktok
    else:
        return 0
416816
def PCA_components(x):
     
    # validate inputs
    try:    
        x = np.array(x)
    except:
        raise ValueError('Impossible to convert x to a numpy array.')
    # eigen values and eigen vectors of data covariance matrix
    eigen_values, eigen_vectors = np.linalg.eig(np.cov(x.T))
    # sort eigen vectors according biggest eigen value
    eigen_order = eigen_vectors.T[(-eigen_values).argsort()]
    # form output - order the eigenvalues
    return eigen_values[(-eigen_values).argsort()]
821434
def bin_number(datapoint, intervals):
  
  index = numpy.searchsorted(intervals, datapoint)
  return [0 if index != i else 1 for i in range(len(intervals) + 1)]
1035509
def n_members(self):
        
        return int(binom(self.n_meas + self.n_elements -1, self.n_elements - 1))
946297
public static int cusolverSpScsreigvsiHost(
        cusolverSpHandle handle, 
        int m, 
        int nnz, 
        cusparseMatDescr descrA, 
        Pointer csrValA, 
        Pointer csrRowPtrA, 
        Pointer csrColIndA, 
        float mu0, 
        Pointer x0, 
        int maxite, 
        float tol, 
        Pointer mu, 
        Pointer x)
    {
        return checkResult(cusolverSpScsreigvsiHostNative(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, mu0, x0, maxite, tol, mu, x));
    }
473229
def getPiLambert(n):
    
    mypi = piGenLambert()
    result = []
    if n > 0:
        result += [next(mypi) for i in range(n)]
    mypi.close()
    return result
1372626
private void computeSpan( List<AssociatedPair> points ) {

		Q.reshape(points.size(), 9);
		int index = 0;

		for( int i = 0; i < points.size(); i++ ) {
			AssociatedPair p = points.get(i);

			Point2D_F64 a = p.p2;
			Point2D_F64 b = p.p1;

			// The points are assumed to be in homogeneous coordinates.  This means z = 1
			Q.data[index++] =  a.x*b.x;
			Q.data[index++] =  a.x*b.y;
			Q.data[index++] =  a.x;
			Q.data[index++] =  a.y*b.x;
			Q.data[index++] =  a.y*b.y;
			Q.data[index++] =  a.y;
			Q.data[index++] =      b.x;
			Q.data[index++] =      b.y;
			Q.data[index++] =  1;
		}

		if( !solverNull.process(Q,4,nullspace) )
			throw new RuntimeException("Nullspace solver should never fail, probably bad input");

		// extract the span of solutions for E from the null space
		for( int i = 0; i < 9; i++ ) {
			X[i] = nullspace.unsafe_get(i,0);
			Y[i] = nullspace.unsafe_get(i,1);
			Z[i] = nullspace.unsafe_get(i,2);
			W[i] = nullspace.unsafe_get(i,3);
		}
	}
201963
public static int cusparseSdense2csc(
        cusparseHandle handle, 
        int m, 
        int n, 
        cusparseMatDescr descrA, 
        Pointer A, 
        int lda, 
        Pointer nnzPerCol, 
        Pointer cscSortedValA, 
        Pointer cscSortedRowIndA, 
        Pointer cscSortedColPtrA)
    {
        return checkResult(cusparseSdense2cscNative(handle, m, n, descrA, A, lda, nnzPerCol, cscSortedValA, cscSortedRowIndA, cscSortedColPtrA));
    }
129671
public static int cusolverSpScsrzfdHost(
        cusolverSpHandle handle, 
        int n, 
        int nnz, 
        cusparseMatDescr descrA, 
        Pointer csrValA, 
        Pointer csrRowPtrA, 
        Pointer csrColIndA, 
        Pointer P, 
        Pointer numnz)
    {
        return checkResult(cusolverSpScsrzfdHostNative(handle, n, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, P, numnz));
    }
89020
def sp_rand(m,n,a):
    
    if m == 0 or n == 0: return spmatrix([], [], [], (m,n))
    nnz = min(max(0, int(round(a*m*n))), m*n)
    nz = matrix(random.sample(range(m*n), nnz), tc='i')
    return spmatrix(normal(nnz,1), nz%m, matrix([int(ii) for ii in nz/m]), (m,n))
68533
def get_predictor(self, n):
        
        l = len(self.predictors)
        if n >= l:
            logger.warn("n > #towers, will assign predictor to GPU by round-robin")
        return [self.predictors[k % l] for k in range(n)]
742488
def rand(n, d=None, r=2, samplefunc=_np.random.randn):
    
    n0 = _np.asanyarray(n, dtype=_np.int32)
    r0 = _np.asanyarray(r, dtype=_np.int32)
    if d is None:
        d = n.size
    if n0.size is 1:
        n0 = _np.ones((d,), dtype=_np.int32) * n0
    if r0.size is 1:
        r0 = _np.ones((d + 1,), dtype=_np.int32) * r0
        r0[0] = 1
        r0[d] = 1
    c = _vector.vector()
    c.d = d
    c.n = n0
    c.r = r0
    c.get_ps()
    c.core = samplefunc(c.ps[d] - 1)
    return c
131998
def get_pca_ks_stats(self, maxrange=5):
        
        pc_to_phenotype_pairs = {}
        num_components = self.principal_observations_df.shape[1]
        if num_components < maxrange:
            maxrange = num_components

        phenotypes = self.principal_observations_df.phenotype.unique().tolist()
        for i in range(0, maxrange):
            phenotype_pair_to_ks = {}
            for p1, p2 in combinations(phenotypes, 2):
                p1_pc = self.principal_observations_df[self.principal_observations_df.phenotype == p1].iloc[:,i].as_matrix()
                p2_pc = self.principal_observations_df[self.principal_observations_df.phenotype == p2].iloc[:,i].as_matrix()
                phenotype_pair_to_ks[(p1, p2)] = ks_2samp(p1_pc, p2_pc)
            pc_to_phenotype_pairs[i + 1] = phenotype_pair_to_ks

        return pc_to_phenotype_pairs
55465
def NIR_calc(P, POP):
    
    try:
        max_P = max(list(P.values()))
        length = POP
        return max_P / length
    except Exception:
        return "None"
568712
def compute_n(ic)

      temp_ic = ImageCoordinate.cloneCoord(ic)

      n = -1  # compensate for 0,0 case

      x_off = [-1,0,1]
      y_off = [-1,0,1]

      x_off.each do |x|
        y_off.each do |y|

          temp_ic[:x] = ic[:x] + x
          temp_ic[:y] = ic[:y] + y

          if @im.inBounds(temp_ic) and @im[temp_ic] == @im[ic] then
            n += 1
          end

        end

      end

      temp_ic.recycle

      n

    end
664721
public static int cusolverSpScsreigvsi(
        cusolverSpHandle handle, 
        int m, 
        int nnz, 
        cusparseMatDescr descrA, 
        Pointer csrValA, 
        Pointer csrRowPtrA, 
        Pointer csrColIndA, 
        float mu0, 
        Pointer x0, 
        int maxite, 
        float eps, 
        Pointer mu, 
        Pointer x)
    {
        return checkResult(cusolverSpScsreigvsiNative(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, mu0, x0, maxite, eps, mu, x));
    }