def count_in_and_out_degree(graph: Graph, nout, nin, nid): out_degree = 0 for edge in graph.out_edge_ids_for_node(nid): out_degree += 1 dst = graph.out_edge_dst(edge) atomic_add(nin, dst, 1) nout[nid] = out_degree
def cc_pull_topo_operator(graph: Graph, changed, comp_current: np.ndarray, nid): for ii in graph.out_edge_ids_for_node(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)
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_for_node(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)
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 compute_pagerank_pull_residual_operator(graph: Graph, delta, residual, nid): total = 0 for ii in graph.out_edge_ids_for_node(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_for_node(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)
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_for_node(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))
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)
def sum_degree_operator( graph: Graph, source_degree, sum_source: ReduceSum[np.uint64], destination_degree, sum_destination: ReduceSum[np.uint64], nid, ): for edge in graph.out_edge_ids_for_node(nid): sum_source.update(source_degree[nid]) dst = graph.out_edge_dst(edge) sum_destination.update(destination_degree[dst])
def degree_assortativity_coefficient_operator( graph: Graph, source_degree, source_average, destination_degree, destination_average, product_of_dev: ReduceSum[float], square_of_source_dev: ReduceSum[float], square_of_destination_dev: ReduceSum[float], nid, ): # deviation of source node from average source_dev = source_degree[nid] - source_average for edge in graph.out_edge_ids_for_node(nid): dst = graph.out_edge_dst(edge) destination_dev = destination_degree[dst] - destination_average product_of_dev.update(source_dev * destination_dev) square_of_source_dev.update(source_dev * source_dev) square_of_destination_dev.update(destination_dev * destination_dev)
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_for_node(nid): dst = graph.out_edge_dst(ii) atomic_add(nout, dst, 1)