(G, seeds)
return (distances, nearest_seed)
Bellman-Ford iteration.

    Parameters
    ----------
    G : sparse matrix
        Directed graph with positive weights.
    seeds : list
        Starting seeds

    Returns
    -------
    distances : array
        Distance of each point to the nearest seed
    nearest_seed : array
        Index of the nearest seed
Bellman-Ford iteration.
Bellman - Ford iteration .
def bellman_ford(G, seeds):
    """Bellman-Ford iteration.

    Parameters
    ----------
    G : sparse matrix
        Directed graph with positive weights.
    seeds : list
        Starting seeds

    Returns
    -------
    distances : array
        Distance of each point to the nearest seed
    nearest_seed : array
        Index of the nearest seed
    """
    G = asgraph(G)
    N = G.shape[0]

    if G.nnz > 0:
        if G.data.min() < 0:
            raise ValueError('Bellman-Ford is defined only for positive weights.')
    if G.dtype == complex:
        raise ValueError('Bellman-Ford is defined only for real weights.')

    seeds = np.asarray(seeds, dtype='intc')

    distances = np.full(N, np.inf, dtype=G.dtype)
    distances[seeds] = 0

    nearest_seed = np.full(N, -1, dtype='intc')
    nearest_seed[seeds] = seeds

    amg_core.bellman_ford(N, G.indptr, G.indices, G.data, distances, nearest_seed)

    return (distances, nearest_seed)
def bellman_ford ( G , seeds ) : G = asgraph ( G ) N = G . shape [ 0 ] if G . nnz > 0 : if G . data . min ( ) < 0 : raise ValueError ( 'Bellman-Ford is defined only for positive weights.' ) if G . dtype == complex : raise ValueError ( 'Bellman-Ford is defined only for real weights.' ) seeds = np . asarray ( seeds , dtype = 'intc' ) distances = np . full ( N , np . inf , dtype = G . dtype ) distances [ seeds ] = 0 nearest_seed = np . full ( N , - 1 , dtype = 'intc' ) nearest_seed [ seeds ] = seeds amg_core . bellman_ford ( N , G . indptr , G . indices , G . data , distances , nearest_seed ) return ( distances , nearest_seed )