Band properties from the eigenvalues as a tuple,
        (band gap, cbm, vbm, is_band_gap_direct).
767896
def eigenvalue_band_properties(self):
        
        vbm = -float("inf")
        vbm_kpoint = None
        cbm = float("inf")
        cbm_kpoint = None
        for spin, d in self.eigenvalues.items():
            for k, val in enumerate(d):
                for (eigenval, occu) in val:
                    if occu > self.occu_tol and eigenval > vbm:
                        vbm = eigenval
                        vbm_kpoint = k
                    elif occu <= self.occu_tol and eigenval < cbm:
                        cbm = eigenval
                        cbm_kpoint = k
        return max(cbm - vbm, 0), cbm, vbm, vbm_kpoint == cbm_kpoint
823184
def band_width(high_data, low_data, period):
    
    catch_errors.check_for_input_len_diff(high_data, low_data)
    diff = np.array(high_data) - np.array(low_data)
    bw = sma(diff, period)
    return bw
908859
def get_correction(self, entry):
        
        eigenvalues = entry.parameters["eigenvalues"]
        kpoint_weights = entry.parameters["kpoint_weights"]
        potalign = entry.parameters["potalign"]
        vbm = entry.parameters["vbm"]
        cbm = entry.parameters["cbm"]

        bf_corr = self.perform_bandfill_corr(eigenvalues, kpoint_weights, potalign, vbm, cbm)

        entry.parameters["bandfilling_meta"] = dict(self.metadata)

        return {"bandfilling": bf_corr}
1204754
def eigenvalues_(self):
        """"""
        utils.validation.check_is_fitted(self, 's_')
        return np.square(self.s_).tolist()
1145532
def multidimensional_discretization(rho, sigma, N=3, method='rouwenhorst', m=2):
    

    # rho is assumed to be a scalar
    # sigma is a positive symmetric matrix
    # N number of points in each non-degenerate dimension
    # m : standard deviations to approximate

    import scipy.linalg
    from itertools import product

    d = sigma.shape[1]

    sigma = sigma.copy()

    zero_columns = np.where(sigma.sum(axis=0)==0)[0]
    for i in zero_columns:
        sigma[i,i] = 1

    L = scipy.linalg.cholesky(sigma)

    N = int(N)

    if method=='tauchen':
        [nodes_1d, probas_1d] = tauchen(N, 0, rho, 1, m=m)
    elif method=='rouwenhorst':
        [nodes_1d, probas_1d] = rouwenhorst(rho, 1, N)

    markov_nodes = np.array( list( product( *([nodes_1d]*d))) ).T
    markov_indices = np.array( list( product( *([range(N)]*d)  )  ) ).T

    markov_nodes = np.dot(L, markov_nodes)


    transition_matrix = 1
    for i in range(d):
        transition_matrix = np.kron(transition_matrix, probas_1d)

    markov_nodes = np.ascontiguousarray(markov_nodes.T)

    for i in zero_columns:
        markov_nodes[:,i] = 0

    return [markov_nodes, transition_matrix]
169217
def band_reorder(self):
        
        eiv = self.eigendisplacements
        eig = self.bands
    
        nphonons,nqpoints = self.bands.shape
        order = np.zeros([nqpoints,nphonons],dtype=int)
        order[0] = np.array(range(nphonons))
        
        #get the atomic masses
        atomic_masses = [ site.specie.atomic_mass for site in self.structure.sites ]
 
        #get order
        for nq in range(1,nqpoints):
            old_eiv = eigenvectors_from_displacements(eiv[:,nq-1],atomic_masses)
            new_eiv = eigenvectors_from_displacements(eiv[:,nq],  atomic_masses)
            order[nq] = estimate_band_connection(old_eiv.reshape([nphonons,nphonons]).T,
                                                 new_eiv.reshape([nphonons,nphonons]).T,
                                                 order[nq-1])

        #reorder
        for nq in range(1,nqpoints):
            eivq=eiv[:,nq]
            eigq=eig[:,nq]
            eiv[:,nq] = eivq[order[nq]]
            eig[:,nq] = eigq[order[nq]]
1112055
def main():
    

    # Eigendecomposition:
    #   (4.537, [-0.971555, -0.0578339+0.229643j])
    #   (0.349, [-0.236813, 0.237270-0.942137j])
    # |b> = (0.64510-0.47848j, 0.35490-0.47848j)
    # |x> = (-0.0662724-0.214548j, 0.784392-0.578192j)
    A = np.array([[4.30213466-6.01593490e-08j,
                   0.23531802+9.34386156e-01j],
                  [0.23531882-9.34388383e-01j,
                   0.58386534+6.01593489e-08j]])
    t = 0.358166*math.pi
    register_size = 4
    input_prep_gates = [cirq.Rx(1.276359), cirq.Rz(1.276359)]
    expected = (0.144130, 0.413217, -0.899154)

    # Set C to be the smallest eigenvalue that can be represented by the
    # circuit.
    C = 2*math.pi / (2**register_size * t)

    # Simulate circuit
    print("Expected observable outputs:")
    print("X =", expected[0])
    print("Y =", expected[1])
    print("Z =", expected[2])
    print("Actual: ")
    simulate(hhl_circuit(A, C, t, register_size, *input_prep_gates))
557750
def sph_harmonic_tp(nrows, ncols, n, m):
    
    nuvec = pysphi.ynunm(n, m, n + 1)
    num = nuvec[1:] * (-1) ** m
    num = num[::-1]
    yvec = np.concatenate([num, nuvec])
    
    theta = np.linspace(0.0, np.pi, nrows)
    phi = np.linspace(0.0, 2.0 * np.pi - 2.0 * np.pi / ncols)
    nu = np.array(range(-n, n + 1), dtype=np.complex128)
    
    out = np.zeros([nrows, ncols], dtype=np.complex128)

    for nn in xrange(0, nrows):
        exp_vec = np.exp(1j * nu * theta[nn])
        for mm in xrange(0, ncols):          
            vl = np.sum(yvec * exp_vec)
            out[nn, mm] = 1j ** m * np.exp(1j * m * phi[mm]) * vl

    return out
1111734
float[] getBandFactors()
	{
		float[] factors = new float[BANDS];
		for (int i=0, maxCount=BANDS; i<maxCount; i++)
		{
			factors[i] = getBandFactor(settings[i]);
		}
		
		return factors;
	}
746142
def _brownian_eigs(n_grid, lag_time, grad_potential, xmin, xmax, reflect_bc):
    
    transmat = _brownian_transmat(n_grid, lag_time, grad_potential, xmin, xmax, reflect_bc)
    u, lv, rv = _solve_msm_eigensystem(transmat, k=len(transmat) - 1)
    return u, rv
537825
def ξ_bounds(self):
        
        λ, Δμ = self._dichalcogenide.λ, self.Δμ
        return (abs(Δμ) - 2 * λ, abs(Δμ))
602614
def laplacian_eigenmaps(self, num_dims=None, normed=True, val_thresh=1e-8):
    '''
    '''
    L = self.laplacian(normed=normed)
    return _null_space(L, num_dims, val_thresh, overwrite=True)
848895
def check_psd(matrix, tolerance=1e-6):
    

    hermitian = (matrix + matrix.T.conjugate()) / 2
    eigenvalues = np.linalg.eigh(hermitian)[0]
    return (eigenvalues > -tolerance).all()
1261167
def eigenvectors_from_displacements(disp,masses):
    
    nphonons,natoms,ndirections = disp.shape
    sqrt_masses = np.sqrt(masses)
    return np.einsum("nax,a->nax",disp,sqrt_masses)
827195
def laplacian_pca(self, coordinates, num_dims=None, beta=0.5):
    ''''''
    X = np.atleast_2d(coordinates)
    L = self.laplacian(normed=True)
    kernel = X.dot(X.T)
    kernel /= eigsh(kernel, k=1, which='LM', return_eigenvectors=False)
    L /= eigsh(L, k=1, which='LM', return_eigenvectors=False)
    W = (1-beta)*(np.identity(kernel.shape[0]) - kernel) + beta*L
    if num_dims is None:
      vals, vecs = np.linalg.eigh(W)
    else:
      vals, vecs = eigh(W, eigvals=(0, num_dims-1), overwrite_a=True)
    return X.T.dot(vecs).dot(vecs.T).T
604224
def B_(self):
        '''
        (n_, n) = self.H.shape
        ls = self.linear_system
        if self._B_ is None or self._B_.shape[1] < n_:
            # compute B_
            if ls.self_adjoint:
                self._B_ = self.C.T.conj()
                if n_ > n:
                    self._B_ = numpy.r_[self._B_,
                                        utils.inner(self.V[:, [-1]],
                                                    self.projection.AU,
                                                    ip_B=ls.ip_B)]
            else:
                self._B_ = utils.inner(self.V, self.projection.AU,
                                       ip_B=ls.ip_B)
        return self._B_
1022008
def get_diagonalizing_basis(list_of_pauli_terms):
    
    qubit_ops = set(reduce(lambda x, y: x + y,
                       [list(term._ops.items()) for term in list_of_pauli_terms]))
    qubit_ops = sorted(list(qubit_ops), key=lambda x: x[0])

    return PauliTerm.from_list(list(map(lambda x: tuple(reversed(x)), qubit_ops)))