dgl.transform.add_self_loop

dgl.transform.add_self_loop(g)[source]

Return a new graph containing all the edges in the input graph plus self loops of every nodes. No duplicate self loop will be added for nodes already having self loops. Self-loop edges id are not preserved. All self-loop edges would be added at the end.

Examples

>>> g = DGLGraph()
>>> g.add_nodes(5)
>>> g.add_edges([0, 1, 2], [1, 1, 2])
>>> new_g = dgl.transform.add_self_loop(g) # Nodes 0, 3, 4 don't have self-loop
>>> new_g.edges()
(tensor([0, 0, 1, 2, 3, 4]), tensor([1, 0, 1, 2, 3, 4]))
Parameters:g (DGLGraph) –
Returns:
Return type:DGLGraph