def _tracemin_fiedler(L, X, normalized, tol, method):
    "Compute the Fiedler vector of L using the TraceMIN-Fiedler algorithm.\n\n    The Fiedler vector of a connected undirected graph is the eigenvector\n    corresponding to the second smallest eigenvalue of the Laplacian matrix of\n    of the graph. This function starts with the Laplacian L, not the Graph.\n\n    Parameters\n    ----------\n    L : Laplacian of a possibly weighted or normalized, but undirected graph\n\n    X : Initial guess for a solution. Usually a matrix of random numbers.\n        This function allows more than one column in X to identify more than\n        one eigenvector if desired.\n\n    normalized : bool\n        Whether the normalized Laplacian matrix is used.\n\n    tol : float\n        Tolerance of relative residual in eigenvalue computation.\n        Warning: There is no limit on number of iterations.\n\n    method : string\n        Should be 'tracemin_pcg', 'tracemin_chol' or 'tracemin_lu'.\n        Otherwise exception is raised.\n\n    Returns\n    -------\n    sigma, X : Two NumPy arrays of floats.\n        The lowest eigenvalues and corresponding eigenvectors of L.\n        The size of input X determines the size of these outputs.\n        As this is for Fiedler vectors, the zero eigenvalue (and\n        constant eigenvector) are avoided.\n    "
    n = X.shape[0]
    if normalized:
        e = sqrt(L.diagonal())
        D = spdiags((1.0 / e), [0], n, n, format='csr')
        L = ((D * L) * D)
        e *= (1.0 / norm(e, 2))
    if normalized:

        def project(X):
            'Make X orthogonal to the nullspace of L.\n            '
            X = asarray(X)
            for j in range(X.shape[1]):
                X[:, j] -= (dot(X[:, j], e) * e)
    else:

        def project(X):
            'Make X orthogonal to the nullspace of L.\n            '
            X = asarray(X)
            for j in range(X.shape[1]):
                X[:, j] -= (X[:, j].sum() / n)
    if (method == 'tracemin_pcg'):
        D = L.diagonal().astype(float)
        solver = _PCGSolver((lambda x: (L * x)), (lambda x: (D * x)))
    elif ((method == 'tracemin_chol') or (method == 'tracemin_lu')):
        A = csc_matrix(L, dtype=float, copy=True)
        i = (A.indptr[1:] - A.indptr[:(- 1)]).argmax()
        A[(i, i)] = float('inf')
        if (method == 'tracemin_chol'):
            solver = _CholeskySolver(A)
        else:
            solver = _LUSolver(A)
    else:
        raise nx.NetworkXError(('Unknown linear system solver: ' + method))
    Lnorm = abs(L).sum(axis=1).flatten().max()
    project(X)
    W = asmatrix(ndarray(X.shape, order='F'))
    while True:
        X = qr(X)[0]
        W[:, :] = (L * X)
        H = (X.T * W)
        (sigma, Y) = eigh(H, overwrite_a=True)
        X *= Y
        res = (dasum(((W * asmatrix(Y)[:, 0]) - (sigma[0] * X[:, 0]))) / Lnorm)
        if (res < tol):
            break
        W[:, :] = solver.solve(X, tol)
        X = (inv((W.T * X)) * W.T).T
        project(X)
    return (sigma, asarray(X))
Compute the Fiedler vector of L using the TraceMIN-Fiedler algorithm.

The Fiedler vector of a connected undirected graph is the eigenvector
corresponding to the second smallest eigenvalue of the Laplacian matrix of
of the graph. This function starts with the Laplacian L, not the Graph.

Parameters
----------
L : Laplacian of a possibly weighted or normalized, but undirected graph

X : Initial guess for a solution. Usually a matrix of random numbers.
    This function allows more than one column in X to identify more than
    one eigenvector if desired.

normalized : bool
    Whether the normalized Laplacian matrix is used.

tol : float
    Tolerance of relative residual in eigenvalue computation.
    Warning: There is no limit on number of iterations.

method : string
    Should be 'tracemin_pcg', 'tracemin_chol' or 'tracemin_lu'.
    Otherwise exception is raised.

Returns
-------
sigma, X : Two NumPy arrays of floats.
    The lowest eigenvalues and corresponding eigenvectors of L.
    The size of input X determines the size of these outputs.
    As this is for Fiedler vectors, the zero eigenvalue (and
    constant eigenvector) are avoided.
def _tracemin_fiedler(L, X, normalized, tol, method):
    "Compute the Fiedler vector of L using the TraceMIN-Fiedler algorithm.\n\n    The Fiedler vector of a connected undirected graph is the eigenvector\n    corresponding to the second smallest eigenvalue of the Laplacian matrix of\n    of the graph. This function starts with the Laplacian L, not the Graph.\n\n    Parameters\n    ----------\n    L : Laplacian of a possibly weighted or normalized, but undirected graph\n\n    X : Initial guess for a solution. Usually a matrix of random numbers.\n        This function allows more than one column in X to identify more than\n        one eigenvector if desired.\n\n    normalized : bool\n        Whether the normalized Laplacian matrix is used.\n\n    tol : float\n        Tolerance of relative residual in eigenvalue computation.\n        Warning: There is no limit on number of iterations.\n\n    method : string\n        Should be 'tracemin_pcg', 'tracemin_chol' or 'tracemin_lu'.\n        Otherwise exception is raised.\n\n    Returns\n    -------\n    sigma, X : Two NumPy arrays of floats.\n        The lowest eigenvalues and corresponding eigenvectors of L.\n        The size of input X determines the size of these outputs.\n        As this is for Fiedler vectors, the zero eigenvalue (and\n        constant eigenvector) are avoided.\n    "
    n = X.shape[0]
    if normalized:
        e = sqrt(L.diagonal())
        D = spdiags((1.0 / e), [0], n, n, format='csr')
        L = ((D * L) * D)
        e *= (1.0 / norm(e, 2))
    if normalized:

        def project(X):
            'Make X orthogonal to the nullspace of L.\n            '
            X = asarray(X)
            for j in range(X.shape[1]):
                X[:, j] -= (dot(X[:, j], e) * e)
    else:

        def project(X):
            'Make X orthogonal to the nullspace of L.\n            '
            X = asarray(X)
            for j in range(X.shape[1]):
                X[:, j] -= (X[:, j].sum() / n)
    if (method == 'tracemin_pcg'):
        D = L.diagonal().astype(float)
        solver = _PCGSolver((lambda x: (L * x)), (lambda x: (D * x)))
    elif ((method == 'tracemin_chol') or (method == 'tracemin_lu')):
        A = csc_matrix(L, dtype=float, copy=True)
        i = (A.indptr[1:] - A.indptr[:(- 1)]).argmax()
        A[(i, i)] = float('inf')
        if (method == 'tracemin_chol'):
            solver = _CholeskySolver(A)
        else:
            solver = _LUSolver(A)
    else:
        raise nx.NetworkXError(('Unknown linear system solver: ' + method))
    Lnorm = abs(L).sum(axis=1).flatten().max()
    project(X)
    W = asmatrix(ndarray(X.shape, order='F'))
    while True:
        X = qr(X)[0]
        W[:, :] = (L * X)
        H = (X.T * W)
        (sigma, Y) = eigh(H, overwrite_a=True)
        X *= Y
        res = (dasum(((W * asmatrix(Y)[:, 0]) - (sigma[0] * X[:, 0]))) / Lnorm)
        if (res < tol):
            break
        W[:, :] = solver.solve(X, tol)
        X = (inv((W.T * X)) * W.T).T
        project(X)
    return (sigma, asarray(X))