MCPcopy Index your code
hub / github.com/dmlc/dgl / remove_edges

Function remove_edges

python/dgl/transforms/functional.py:1751–1823  ·  view source on GitHub ↗

r"""Remove the specified edges and return a new graph. Also delete the features of the edges. The edges must exist in the graph. The resulting graph has the same number of the nodes as the input one, even if some nodes become isolated after the the edge removal. Parameters ----

(g, eids, etype=None, store_ids=False)

Source from the content-addressed store, hash-verified

1749
1750
1751def remove_edges(g, eids, etype=None, store_ids=False):
1752 r"""Remove the specified edges and return a new graph.
1753
1754 Also delete the features of the edges. The edges must exist in the graph.
1755 The resulting graph has the same number of the nodes as the input one,
1756 even if some nodes become isolated after the the edge removal.
1757
1758 Parameters
1759 ----------
1760 eids : int, Tensor, iterable[int]
1761 The IDs of the edges to remove.
1762 etype : str or (str, str, str), optional
1763 The type names of the edges. The allowed type name formats are:
1764
1765 * ``(str, str, str)`` for source node type, edge type and destination node type.
1766 * or one ``str`` edge type name if the name can uniquely identify a
1767 triplet format in the graph.
1768
1769 Can be omitted if the graph has only one type of edges.
1770 store_ids : bool, optional
1771 If True, it will store the raw IDs of the extracted nodes and edges in the ``ndata``
1772 and ``edata`` of the resulting graph under name ``dgl.NID`` and ``dgl.EID``,
1773 respectively.
1774
1775 Return
1776 ------
1777 DGLGraph
1778 The graph with edges deleted.
1779
1780 Notes
1781 -----
1782 This function preserves the batch information.
1783
1784 Examples
1785 --------
1786 >>> import dgl
1787 >>> import torch
1788
1789 **Homogeneous Graphs**
1790
1791 >>> g = dgl.graph((torch.tensor([0, 0, 2]), torch.tensor([0, 1, 2])))
1792 >>> g.edata['he'] = torch.arange(3).float().reshape(-1, 1)
1793 >>> g = dgl.remove_edges(g, torch.tensor([0, 1]))
1794 >>> g
1795 Graph(num_nodes=3, num_edges=1,
1796 ndata_schemes={}
1797 edata_schemes={'he': Scheme(shape=(1,), dtype=torch.float32)})
1798 >>> g.edges('all')
1799 (tensor([2]), tensor([2]), tensor([0]))
1800 >>> g.edata['he']
1801 tensor([[2.]])
1802
1803 **Heterogeneous Graphs**
1804
1805 >>> g = dgl.heterograph({
1806 ... ('user', 'plays', 'game'): (torch.tensor([0, 1, 1, 2]),
1807 ... torch.tensor([0, 0, 1, 1])),
1808 ... ('developer', 'develops', 'game'): (torch.tensor([0, 1]),

Callers 3

knn_graphFunction · 0.85
segmented_knn_graphFunction · 0.85
remove_self_loopFunction · 0.85

Calls 2

remove_edgesMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected