def find_fiedler(L, x, normalized, tol):
    L = csc_matrix(L, dtype=float)
    n = L.shape[0]
    if normalized:
        D = spdiags((1.0 / sqrt(L.diagonal())), [0], n, n, format='csc')
        L = ((D * L) * D)
    if ((method == 'lanczos') or (n < 10)):
        (sigma, X) = eigsh(L, 2, which='SM', tol=tol, return_eigenvectors=True)
        return (sigma[1], X[:, 1])
    else:
        X = asarray(asmatrix(x).T)
        M = spdiags((1.0 / L.diagonal()), [0], n, n)
        Y = ones(n)
        if normalized:
            Y /= D.diagonal()
        (sigma, X) = lobpcg(L, X, M=M, Y=asmatrix(Y).T, tol=tol, maxiter=n, largest=False)
        return (sigma[0], X[:, 0])
def find_fiedler(L, x, normalized, tol):
    L = csc_matrix(L, dtype=float)
    n = L.shape[0]
    if normalized:
        D = spdiags((1.0 / sqrt(L.diagonal())), [0], n, n, format='csc')
        L = ((D * L) * D)
    if ((method == 'lanczos') or (n < 10)):
        (sigma, X) = eigsh(L, 2, which='SM', tol=tol, return_eigenvectors=True)
        return (sigma[1], X[:, 1])
    else:
        X = asarray(asmatrix(x).T)
        M = spdiags((1.0 / L.diagonal()), [0], n, n)
        Y = ones(n)
        if normalized:
            Y /= D.diagonal()
        (sigma, X) = lobpcg(L, X, M=M, Y=asmatrix(Y).T, tol=tol, maxiter=n, largest=False)
        return (sigma[0], X[:, 0])