dgl.transform.to_bidirected¶

dgl.transform.
to_bidirected
(g, readonly=True)[source]¶ Convert the graph to a bidirected graph.
The function generates a new graph with no node/edge feature. If g has m edges for i>j and n edges for j>i, then the returned graph will have max(m, n) edges for both i>j and j>i.
Parameters: Returns: Return type: Examples
The following two examples use PyTorch backend, one for nonmulti graph and one for multigraph.
>>> # nonmulti 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]))
>>> # multigraph >>> g.add_edges([0, 1], [1, 0]) >>> g.edges() (tensor([0, 0, 0, 1]), tensor([0, 1, 1, 0]))
>>> bg2 = dgl.to_bidirected(g) >>> bg2.edges() (tensor([0, 1, 1, 0, 0]), tensor([0, 0, 0, 1, 1]))