[Networkit] Efficient ways to load edges from NumPy arrays

Ivan Raikov ivan.g.raikov at gmail.com
Tue Jul 25 22:40:17 CEST 2017


Hello,

I would like to load a directed graph into NetworKit from an
HDF5-based sparse graph representation. I am able to load the source
and destination indices in numpy arrays, and then used a generator and
GraphUpdater to iterate over the edges and instantiate the graph:

h5g = load_h5graph(input_file)

def graph_stream(h5g):
    for (sources, destinations) in h5g.items():
            ## sources and destinations are uint32 numpy arrays
            for (src,dst) in zip(sources,destinations):
                yield (GraphEvent(GraphEvent.EDGE_ADDITION, src, dst, 1.0))

g = Graph(n_nodes, False, True)
gu = GraphUpdater(g)
gu.update(graph_stream(h5g))

This worked for a graph with about 1e6 edges, although I have not yet
tested with larger graphs. I was wondering if anyone could recommend
better ways to do this. Thanks and best regards,

-Ivan



More information about the NetworKit mailing list