MCPcopy
hub / github.com/dmlc/dgl / add_reverse_edges

Function add_reverse_edges

python/dgl/transforms/functional.py:878–1054  ·  view source on GitHub ↗

r"""Add a reversed edge for each edge in the input graph and return a new graph. For a graph with edges :math:`(i_1, j_1), \cdots, (i_n, j_n)`, this function creates a new graph with edges :math:`(i_1, j_1), \cdots, (i_n, j_n), (j_1, i_1), \cdots, (j_n, i_n)`. The returned graph ma

(
    g,
    readonly=None,
    copy_ndata=True,
    copy_edata=False,
    ignore_bipartite=False,
    exclude_self=True,
)

Source from the content-addressed store, hash-verified

876
877
878def add_reverse_edges(
879 g,
880 readonly=None,
881 copy_ndata=True,
882 copy_edata=False,
883 ignore_bipartite=False,
884 exclude_self=True,
885):
886 r"""Add a reversed edge for each edge in the input graph and return a new graph.
887
888 For a graph with edges :math:`(i_1, j_1), \cdots, (i_n, j_n)`, this
889 function creates a new graph with edges
890 :math:`(i_1, j_1), \cdots, (i_n, j_n), (j_1, i_1), \cdots, (j_n, i_n)`.
891
892 The returned graph may have duplicate edges. To create a bidirected graph without
893 duplicate edges, use :func:`to_bidirected`.
894
895 The operation only works for edges whose two endpoints belong to the same node type.
896 DGL will raise error if the input graph is heterogeneous and contains edges
897 with different types of endpoints. If :attr:`ignore_bipartite` is true, DGL will
898 ignore those edges instead.
899
900 Parameters
901 ----------
902 g : DGLGraph
903 The input graph.
904 readonly : bool, default to be True
905 Deprecated. There will be no difference between readonly and non-readonly
906 copy_ndata: bool, optional
907 If True, the node features of the new graph are copied from
908 the original graph. If False, the new graph will not have any
909 node features.
910
911 (Default: True)
912 copy_edata: bool, optional
913 If True, the features of the reversed edges will be identical to
914 the original ones.
915
916 If False, the new graph will not have any edge features.
917
918 (Default: False)
919 ignore_bipartite: bool, optional
920 If True, unidirectional bipartite graphs are ignored and
921 no error is raised. If False, an error will be raised if
922 an edge type of the input heterogeneous graph is for a unidirectional
923 bipartite graph.
924 exclude_self: bool, optional
925 If True, it does not add reverse edges for self-loops, which is likely
926 meaningless in most cases.
927
928 Returns
929 -------
930 DGLGraph
931 The graph with reversed edges added.
932
933 Notes
934 -----
935 If :attr:`copy_ndata` is True, the resulting graph will share the node feature

Callers 1

to_bidirectedFunction · 0.70

Calls 8

dgl_warningFunction · 0.85
add_for_etypeFunction · 0.85
formatMethod · 0.80
appendMethod · 0.80
num_nodesMethod · 0.45
edgesMethod · 0.45
copy_toMethod · 0.45
num_edgesMethod · 0.45

Tested by

no test coverage detected