Exemple #1
0
def calculate_degree(graph: PropertyGraph,
                     in_degree_property,
                     out_degree_property,
                     weight_property=None):
    """
    Calculate the (potentially weighted) in and out degrees of a graph.
    The function will modify the given graph by adding two new node properties,
    one for the in degree and one for the out degree. Nothing is returned.
    Parameters:
        graph: a PropertyGraph
        in_degree_property: the property name for the in degree
        out_degree_property: the property name for the out degree
        weight_property: an edge property to use in calculating the weighted degree
    """
    num_nodes = graph.num_nodes()
    nout = LargeArray[np.uint64](num_nodes, AllocationPolicy.INTERLEAVED)
    nin = LargeArray[np.uint64](num_nodes, AllocationPolicy.INTERLEAVED)

    do_all(range(num_nodes), initialize_in_degree(nin.as_numpy()), steal=False)

    # are we calculating weighted degree?
    if not weight_property:
        count_operator = count_in_and_out_degree(graph, nout.as_numpy(),
                                                 nin.as_numpy())
    else:
        count_operator = count_weighted_in_and_out_degree(
            graph, nout.as_numpy(), nin.as_numpy(),
            graph.get_edge_property(weight_property))
    do_all(range(num_nodes), count_operator, steal=True)

    graph.add_node_property(
        pyarrow.table({
            in_degree_property: nin,
            out_degree_property: nout
        }))
Exemple #2
0
def create_distance_array(g: PropertyGraph, source, length_property):
    a = np.empty(len(g),
                 dtype=dtype_of_pyarrow_array(
                     g.get_edge_property(length_property)))
    # TODO(amp): Remove / 4
    infinity = dtype_info(a.dtype).max / 4
    a[:] = infinity
    a[source] = 0
    return a
Exemple #3
0
def sssp(graph: PropertyGraph, source, length_property, shift, property_name):
    dists = create_distance_array(graph, source, length_property)

    # Define the struct type here so it can depend on the type of the weight property
    UpdateRequest = np.dtype([("src", np.uint32), ("dist", dists.dtype)])

    init_bag = InsertBag[UpdateRequest]()
    init_bag.push((source, 0))

    t = StatTimer("Total SSSP")
    t.start()
    for_each(
        init_bag,
        sssp_operator(graph, dists, graph.get_edge_property(length_property)),
        worklist=OrderedByIntegerMetric(obim_indexer(shift)),
        disable_conflict_detection=True,
        loop_name="SSSP",
    )
    t.stop()
    print("Elapsed time: ", t.get(), "milliseconds.")

    graph.add_node_property(pyarrow.table({property_name: dists}))