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

Method remove_edges

python/dgl/heterograph.py:629–761  ·  view source on GitHub ↗

r"""Remove multiple edges with the specified edge type Nodes will not be removed. After removing edges, the rest edges will be re-indexed using consecutive integers from 0, with their relative order preserved. The features for the removed edges will be removed accor

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

Source from the content-addressed store, hash-verified

627 self._reset_cached_info()
628
629 def remove_edges(self, eids, etype=None, store_ids=False):
630 r"""Remove multiple edges with the specified edge type
631
632 Nodes will not be removed. After removing edges, the rest
633 edges will be re-indexed using consecutive integers from 0,
634 with their relative order preserved.
635
636 The features for the removed edges will be removed accordingly.
637
638 Parameters
639 ----------
640 eids : int, tensor, numpy.ndarray, list
641 IDs for the edges to remove.
642 etype : str or tuple of str, optional
643 The type of the edges to remove. Can be omitted if there is
644 only one edge type in the graph.
645 store_ids : bool, optional
646 If True, it will store the raw IDs of the extracted nodes and edges in the ``ndata``
647 and ``edata`` of the resulting graph under name ``dgl.NID`` and ``dgl.EID``,
648 respectively.
649
650 Notes
651 -----
652 This function preserves the batch information.
653
654 Examples
655 --------
656
657 >>> import dgl
658 >>> import torch
659
660 **Homogeneous Graphs or Heterogeneous Graphs with A Single Edge Type**
661
662 >>> g = dgl.graph((torch.tensor([0, 0, 2]), torch.tensor([0, 1, 2])))
663 >>> g.edata['he'] = torch.arange(3).float().reshape(-1, 1)
664 >>> g.remove_edges(torch.tensor([0, 1]))
665 >>> g
666 Graph(num_nodes=3, num_edges=1,
667 ndata_schemes={}
668 edata_schemes={'he': Scheme(shape=(1,), dtype=torch.float32)})
669 >>> g.edges('all')
670 (tensor([2]), tensor([2]), tensor([0]))
671 >>> g.edata['he']
672 tensor([[2.]])
673
674 Removing edges from a batched graph preserves batch information.
675
676 >>> g = dgl.graph((torch.tensor([0, 0, 2]), torch.tensor([0, 1, 2])))
677 >>> g2 = dgl.graph((torch.tensor([1, 2, 3]), torch.tensor([1, 3, 4])))
678 >>> bg = dgl.batch([g, g2])
679 >>> bg.batch_num_edges()
680 tensor([3, 3])
681 >>> bg.remove_edges([1, 4])
682 >>> bg.batch_num_edges()
683 tensor([2, 2])
684
685 **Heterogeneous Graphs with Multiple Edge Types**
686

Callers 15

build_graph_trainFunction · 0.95
__call__Method · 0.80
__call__Method · 0.80
remove_edgesFunction · 0.80
test_hetero_convFunction · 0.80
test_empty_queryFunction · 0.80
test_remove_edgesFunction · 0.80
test_edge_removalFunction · 0.80
test_edge_frameFunction · 0.80
test_issue1287Function · 0.80

Calls 8

num_edgesMethod · 0.95
to_canonical_etypeMethod · 0.95
edgesMethod · 0.95
DGLErrorClass · 0.85
number_of_etypesMethod · 0.80
formatMethod · 0.80
astypeMethod · 0.45
edge_subgraphMethod · 0.45

Tested by 11

test_hetero_convFunction · 0.64
test_empty_queryFunction · 0.64
test_remove_edgesFunction · 0.64
test_edge_removalFunction · 0.64
test_edge_frameFunction · 0.64
test_issue1287Function · 0.64
test_remove_edgesFunction · 0.64
test_hetero_convFunction · 0.64
test_hetero_convFunction · 0.64