(G, algo='serial', k=None)
return mis
Compute a maximal independent vertex set for a graph.

    Parameters
    ----------
    G : sparse matrix
        Symmetric matrix, preferably in sparse CSR or CSC format
        The nonzeros of G represent the edges of an undirected graph.
    algo : {'serial', 'parallel'}
        Algorithm used to compute the MIS
            * serial   : greedy serial algorithm
            * parallel : variant of Luby's parallel MIS algorithm

    Returns
    -------
    S : array
        S[i] = 1 if vertex i is in the MIS
        S[i] = 0 otherwise

    Notes
    -----
    Diagonal entries in the G (self loops) will be ignored.

    Luby's algorithm is significantly more expensive than the
    greedy serial algorithm.
Compute a maximal independent vertex set for a graph.
Compute a maximal independent vertex set for a graph .
def maximal_independent_set(G, algo='serial', k=None):
    """Compute a maximal independent vertex set for a graph.

    Parameters
    ----------
    G : sparse matrix
        Symmetric matrix, preferably in sparse CSR or CSC format
        The nonzeros of G represent the edges of an undirected graph.
    algo : {'serial', 'parallel'}
        Algorithm used to compute the MIS
            * serial   : greedy serial algorithm
            * parallel : variant of Luby's parallel MIS algorithm

    Returns
    -------
    S : array
        S[i] = 1 if vertex i is in the MIS
        S[i] = 0 otherwise

    Notes
    -----
    Diagonal entries in the G (self loops) will be ignored.

    Luby's algorithm is significantly more expensive than the
    greedy serial algorithm.

    """
    G = asgraph(G)
    N = G.shape[0]

    mis = np.empty(N, dtype='intc')
    mis[:] = -1

    if k is None:
        if algo == 'serial':
            fn = amg_core.maximal_independent_set_serial
            fn(N, G.indptr, G.indices, -1, 1, 0, mis)
        elif algo == 'parallel':
            fn = amg_core.maximal_independent_set_parallel
            fn(N, G.indptr, G.indices, -1, 1, 0, mis, np.random.rand(N), -1)
        else:
            raise ValueError(f'Unknown algorithm ({algo})')
    else:
        fn = amg_core.maximal_independent_set_k_parallel
        fn(N, G.indptr, G.indices, k, mis, np.random.rand(N), -1)

    return mis
def maximal_independent_set ( G , algo = 'serial' , k = None ) : G = asgraph ( G ) N = G . shape [ 0 ] mis = np . empty ( N , dtype = 'intc' ) mis [ : ] = - 1 if k is None : if algo == 'serial' : fn = amg_core . maximal_independent_set_serial fn ( N , G . indptr , G . indices , - 1 , 1 , 0 , mis ) elif algo == 'parallel' : fn = amg_core . maximal_independent_set_parallel fn ( N , G . indptr , G . indices , - 1 , 1 , 0 , mis , np . random . rand ( N ) , - 1 ) else : raise ValueError ( f'Unknown algorithm ({algo})' ) else : fn = amg_core . maximal_independent_set_k_parallel fn ( N , G . indptr , G . indices , k , mis , np . random . rand ( N ) , - 1 ) return mis