Exemple #1
0
def test_node_labels_subgraph():
    adj_matrix = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]
    node_labels = np.array(['a', 'b', 'c'])
    g = DiGraph(adj_matrix, node_labels=node_labels)
    nodes = [1, 2]

    assert_array_equal(g.subgraph(nodes).node_labels, node_labels[nodes])
Exemple #2
0
def test_subgraph_weighted():
    adj_matrix = np.arange(3**2).reshape(3, 3)
    g = DiGraph(adj_matrix, weighted=True)
    nodes = [0, 1]

    subgraph_adj_matrix = [[0, 1], [3, 4]]
    assert_array_equal(
        g.subgraph(nodes).csgraph.toarray(), subgraph_adj_matrix)
Exemple #3
0
def test_subgraph():
    adj_matrix = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]
    g = DiGraph(adj_matrix)
    nodes = [1, 2]

    subgraph_adj_matrix = [[False, True], [False, False]]
    assert_array_equal(
        g.subgraph(nodes).csgraph.toarray(), subgraph_adj_matrix)
def test_subgraph_weighted():
    adj_matrix = np.arange(3**2).reshape(3, 3)
    g = DiGraph(adj_matrix, weighted=True)
    nodes = [0, 1]

    subgraph_adj_matrix = [[0, 1], [3, 4]]
    assert_array_equal(
        g.subgraph(nodes).csgraph.toarray(),
        subgraph_adj_matrix
    )
def test_subgraph():
    adj_matrix = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]
    g = DiGraph(adj_matrix)
    nodes = [1, 2]

    subgraph_adj_matrix = [[False, True], [False, False]]
    assert_array_equal(
        g.subgraph(nodes).csgraph.toarray(),
        subgraph_adj_matrix
    )
def test_node_labels_subgraph():
    adj_matrix = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]
    node_labels = np.array(['a', 'b', 'c'])
    g = DiGraph(adj_matrix, node_labels=node_labels)
    nodes = [1, 2]

    assert_array_equal(
        g.subgraph(nodes).node_labels,
        node_labels[nodes]
    )
Exemple #7
0
 def setUp(self):
     """Setup Digraph instances"""
     self.graphs = Graphs()
     for graph_dict in self.graphs.graph_dicts:
         try:
             weighted = graph_dict['weighted']
         except:
             weighted = False
         graph_dict['g'] = DiGraph(graph_dict['A'], weighted=weighted)
Exemple #8
0
def test_node_labels_cyclic_components():
    adj_matrix = [[0, 1], [1, 0]]
    node_labels = np.array(['a', 'b'])
    g = DiGraph(adj_matrix, node_labels=node_labels)

    cyclic_components = [[0], [1]]

    properties = ['cyclic_components']
    suffix = '_indices'
    for prop0, components_ind in zip(properties, [cyclic_components]):
        for return_indices in [True, False]:
            if return_indices:
                components = components_ind
                prop = prop0 + suffix
            else:
                components = [node_labels[i] for i in components_ind]
                prop = prop0
            list_of_array_equal(sorted(getattr(g, prop), key=lambda x: x[0]),
                                sorted(components, key=lambda x: x[0]))
Exemple #9
0
def test_raises_value_error_non_sym():
    """Test with non symmetric input"""
    DiGraph(np.array([[0.4, 0.6]]))