dgl.to_bidirected_stale¶
-
dgl.
to_bidirected_stale
(g, readonly=True)[source]¶ NOTE: this function only works on the deprecated
dgl.DGLGraphStale
object.Convert the graph to a bidirected graph.
The function generates a new graph with no node/edge feature. If g has an edge for
(u, v)
but no edge for(v, u)
, then the returned graph will have both(u, v)
and(v, u)
.If the input graph is a multigraph (there are multiple edges from node u to node v), the returned graph isn’t well defined.
- Parameters
g (DGLGraphStale) – The input graph.
readonly (bool) –
Whether the returned bidirected graph is readonly or not.
(Default: True)
Notes
Please make sure g is a simple graph, otherwise the return value is undefined.
This function discards the batch information. Please use
dgl.DGLGraph.set_batch_num_nodes()
anddgl.DGLGraph.set_batch_num_edges()
on the transformed graph to maintain the information.- Returns
- Return type
Examples
The following two examples use PyTorch backend, one for non-multi graph and one for multi-graph.
>>> g = dgl._deprecate.graph.DGLGraph() >>> g.add_nodes(2) >>> g.add_edges([0, 0], [0, 1]) >>> bg1 = dgl.to_bidirected_stale(g) >>> bg1.edges() (tensor([0, 1, 0]), tensor([0, 0, 1]))