コード例 #1
0
def test_from_igraph_invalid_attribute():
    n = 100
    m = 500
    K = np.zeros((n, n))
    for _ in range(m):
        e = np.random.choice(n, 2, replace=False)
        K[e[0], e[1]] = K[e[1], e[0]] = 1
    g = igraph.Graph.Adjacency(K.tolist())
    G = graphtools.from_igraph(g, attribute="invalid")
コード例 #2
0
def test_from_igraph_weighted():
    n = 100
    m = 500
    K = np.zeros((n, n))
    for _ in range(m):
        e = np.random.choice(n, 2, replace=False)
        K[e[0], e[1]] = K[e[1], e[0]] = np.random.uniform(0, 1)
    g = igraph.Graph.Weighted_Adjacency(K.tolist())
    G = graphtools.from_igraph(g)
    G2 = graphtools.Graph(K, precomputed="adjacency")
    assert np.all(G.K == G2.K)
コード例 #3
0
def test_from_igraph():
    n = 100
    m = 500
    K = np.zeros((n, n))
    for _ in range(m):
        e = np.random.choice(n, 2, replace=False)
        K[e[0], e[1]] = K[e[1], e[0]] = 1
    g = igraph.Graph.Adjacency(K.tolist())
    G = graphtools.from_igraph(g, attribute=None)
    G2 = graphtools.Graph(K, precomputed="adjacency")
    assert np.all(G.K == G2.K)
コード例 #4
0
def test_from_igraph_invalid_attribute():
    with assert_warns_message(
            UserWarning,
            "Edge attribute invalid not found. Returning unweighted graph"):
        n = 100
        m = 500
        K = np.zeros((n, n))
        for _ in range(m):
            e = np.random.choice(n, 2, replace=False)
            K[e[0], e[1]] = K[e[1], e[0]] = 1
        g = igraph.Graph.Adjacency(K.tolist())
        G = graphtools.from_igraph(g, attribute="invalid")
コード例 #5
0
def test_from_igraph_invalid_precomputed():
    with assert_warns_message(
            UserWarning,
            "Cannot build graph from igraph with precomputed=affinity. Use 'adjacency' instead.",
    ):
        n = 100
        m = 500
        K = np.zeros((n, n))
        for _ in range(m):
            e = np.random.choice(n, 2, replace=False)
            K[e[0], e[1]] = K[e[1], e[0]] = 1
        g = igraph.Graph.Adjacency(K.tolist())
        G = graphtools.from_igraph(g, attribute=None, precomputed="affinity")