Convert the graph to a bidirected graph.
The function generates a new graph with no node/edge feature. If g has an edge for i->j but no edge for j->i, then the returned graph will have both i->j and j->i.
If the input graph is a multigraph (there are multiple edges from node i to node j), the returned graph isn’t well defined.
Please make sure g is a single graph, otherwise the return value is undefined.
Returns: Return type: DGLGraph
The following two examples use PyTorch backend, one for non-multi graph and one for multi-graph.
>>> g = dgl.DGLGraph() >>> g.add_nodes(2) >>> g.add_edges([0, 0], [0, 1]) >>> bg1 = dgl.to_bidirected(g) >>> bg1.edges() (tensor([0, 1, 0]), tensor([0, 0, 1]))