Example #1
0
def test_sort_nodes_by_degree(graph: Graph):
    sort_nodes_by_degree(graph)
    assert len(graph.out_edge_ids(0)) == 103
    last_node_n_edges = 103
    for n in range(1, NODES_TO_SAMPLE):
        v = len(graph.out_edge_ids(n))
        assert v <= last_node_n_edges
        last_node_n_edges = v
Example #2
0
def test_sort_all_edges_by_dest(graph: Graph):
    original_dests = [[graph.get_edge_dst(e) for e in graph.out_edge_ids(n)]
                      for n in range(NODES_TO_SAMPLE)]
    mapping = sort_all_edges_by_dest(graph)
    new_dests = [[graph.get_edge_dst(e) for e in graph.out_edge_ids(n)]
                 for n in range(NODES_TO_SAMPLE)]
    for n in range(NODES_TO_SAMPLE):
        assert len(original_dests[n]) == len(new_dests[n])
        my_mapping = [mapping[e] for e in graph.out_edge_ids(n)]
        for i, _ in enumerate(my_mapping):
            assert original_dests[n][i] == new_dests[n][
                my_mapping[i] - graph.out_edge_ids(n)[0]]
        original_dests[n].sort()

        assert original_dests[n] == new_dests[n]
Example #3
0
def count_in_and_out_degree(graph: Graph, nout, nin, nid):
    out_degree = 0
    for edge in graph.out_edge_ids(nid):
        out_degree += 1
        dst = graph.out_edge_dst(edge)
        atomic_add(nin, dst, 1)
    nout[nid] = out_degree
Example #4
0
def count_weighted_in_and_out_degree(graph: Graph, nout, nin, weight_array, nid):
    out_degree = 0
    for edge in graph.out_edge_ids(nid):
        weight = weight_array[edge]
        out_degree += weight
        dst = graph.out_edge_dst(edge)
        atomic_add(nin, dst, weight)
    nout[nid] = out_degree
def cc_pull_topo_operator(graph: Graph, changed, comp_current: np.ndarray,
                          nid):
    for ii in graph.out_edge_ids(nid):
        dst = graph.out_edge_dst(ii)
        # Pull the minimum component from your neighbors
        if comp_current[nid] > comp_current[dst]:
            comp_current[nid] = comp_current[dst]
            # Indicates that update happened
            changed.update(True)
Example #6
0
def compute_async_kcore_operator(graph: Graph, current_degree, k_core_num, nid,
                                 ctx):
    # Decrement degree of all the neighbors of dead node
    for ii in graph.out_edge_ids(nid):
        dst = graph.out_edge_dst(ii)
        old_degree = atomic_sub(current_degree, dst, 1)
        # Add new dead nodes to the worklist
        if old_degree == k_core_num:
            ctx.push(dst)
Example #7
0
def compute_pagerank_pull_residual_operator(graph: Graph, delta, residual,
                                            nid):
    total = 0
    for ii in graph.out_edge_ids(nid):
        dst = graph.out_edge_dst(ii)
        if delta[dst] > 0:
            total += delta[dst]

    if total > 0:
        residual[nid] = total
def cc_push_topo_operator(graph: Graph, changed, comp_current: np.ndarray,
                          comp_old: np.ndarray, nid):
    if comp_old[nid] > comp_current[nid]:
        comp_old[nid] = comp_current[nid]
        # Indicates that update happened
        changed.update(True)
        for ii in graph.out_edge_ids(nid):
            dst = graph.out_edge_dst(ii)
            new_comp = comp_current[nid]
            # Push the minimum component to your neighbors
            atomic_min(comp_current, dst, new_comp)
Example #9
0
def sssp_operator(g: Graph, dists: np.ndarray, edge_weights, item,
                  ctx: UserContext):
    if dists[item.src] < item.dist:
        return
    for ii in g.out_edge_ids(item.src):
        dst = g.out_edge_dst(ii)
        edge_length = edge_weights[ii]
        new_distance = edge_length + dists[item.src]
        old_distance = atomic_min(dists, dst, new_distance)
        if new_distance < old_distance:
            ctx.push((dst, new_distance))
Example #10
0
def bfs_sync_operator_pg(
    graph: Graph,
    next_level: InsertBag[np.uint64],
    next_level_number: int,
    distance: np.ndarray,
    nid,
):
    for ii in graph.out_edge_ids(nid):
        dst = graph.out_edge_dst(ii)
        if distance[dst] == distance_infinity:
            distance[dst] = next_level_number
            next_level.push(dst)
Example #11
0
def test_triangle_count():
    graph = Graph(get_rdg_dataset("rmat15_cleaned_symmetric"))
    original_first_edge_list = [
        graph.get_edge_dst(e) for e in graph.out_edge_ids(0)
    ]
    n = triangle_count(graph)
    assert n == 282617

    n = triangle_count(graph, TriangleCountPlan.node_iteration())
    assert n == 282617

    n = triangle_count(graph, TriangleCountPlan.edge_iteration())
    assert n == 282617

    assert [graph.get_edge_dst(e)
            for e in graph.out_edge_ids(0)] == original_first_edge_list

    sort_all_edges_by_dest(graph)
    n = triangle_count(graph,
                       TriangleCountPlan.ordered_count(edges_sorted=True))
    assert n == 282617
Example #12
0
def test_subgraph_extraction():
    graph = Graph(get_rdg_dataset("rmat15_cleaned_symmetric"))
    sort_all_edges_by_dest(graph)
    nodes = [1, 3, 11, 120]

    expected_edges = [[
        nodes.index(graph.get_edge_dst(e)) for e in graph.out_edge_ids(i)
        if graph.get_edge_dst(e) in nodes
    ] for i in nodes]

    pg = subgraph_extraction(graph, nodes)

    assert isinstance(pg, Graph)
    assert pg.num_nodes() == len(nodes)
    assert pg.num_edges() == 6

    for i, _ in enumerate(expected_edges):
        assert len(pg.out_edge_ids(i)) == len(expected_edges[i])
        assert [pg.get_edge_dst(e)
                for e in pg.out_edge_ids(i)] == expected_edges[i]
Example #13
0
def compute_degree_count_operator(graph: Graph, current_degree, nid):
    """
    Operator to initialize degree fields in graph with current degree. Since symmetric,
    out edge count is equivalent to in-edge count.
    """
    current_degree[nid] = len(graph.out_edge_ids(nid))
Example #14
0
def compute_out_deg_operator(graph: Graph, nout, nid):
    """Operator for computing outdegree of nodes in the Graph"""
    for ii in graph.out_edge_ids(nid):
        dst = graph.out_edge_dst(ii)
        atomic_add(nout, dst, 1)