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

Method num_edges

python/dgl/heterograph.py:2685–2743  ·  view source on GitHub ↗

Return the number of edges in the graph. Parameters ---------- etype : str or (str, str, str), optional The type name of the edges. The allowed type name formats are: * ``(str, str, str)`` for source node type, edge type and destination node type.

(self, etype=None)

Source from the content-addressed store, hash-verified

2683 return self.num_edges(etype)
2684
2685 def num_edges(self, etype=None):
2686 """Return the number of edges in the graph.
2687
2688 Parameters
2689 ----------
2690 etype : str or (str, str, str), optional
2691 The type name of the edges. The allowed type name formats are:
2692
2693 * ``(str, str, str)`` for source node type, edge type and destination node type.
2694 * or one ``str`` edge type name if the name can uniquely identify a
2695 triplet format in the graph.
2696
2697 If not provided, return the total number of edges regardless of the types
2698 in the graph.
2699
2700 Returns
2701 -------
2702 int
2703 The number of edges.
2704
2705 Examples
2706 --------
2707
2708 The following example uses PyTorch backend.
2709
2710 >>> import dgl
2711 >>> import torch
2712
2713 Create a graph with three canonical edge types.
2714
2715 >>> g = dgl.heterograph({
2716 ... ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
2717 ... ('user', 'follows', 'game'): (torch.tensor([0, 1, 2]), torch.tensor([1, 2, 3])),
2718 ... ('user', 'plays', 'game'): (torch.tensor([1, 3]), torch.tensor([2, 3]))
2719 ... })
2720
2721 Query for the number of edges.
2722
2723 >>> g.num_edges('plays')
2724 2
2725 >>> g.num_edges()
2726 7
2727
2728 Use a canonical edge type instead when there is ambiguity for an edge type.
2729
2730 >>> g.num_edges(('user', 'follows', 'user'))
2731 2
2732 >>> g.num_edges(('user', 'follows', 'game'))
2733 3
2734 """
2735 if etype is None:
2736 return sum(
2737 [
2738 self._graph.num_edges(etid)
2739 for etid in range(len(self.canonical_etypes))
2740 ]
2741 )
2742 else:

Callers 15

__repr__Method · 0.95
remove_edgesMethod · 0.95
batch_num_edgesMethod · 0.95
number_of_edgesMethod · 0.95
find_edgesMethod · 0.95
filter_edgesMethod · 0.95
_read_graphFunction · 0.45
_chunk_graphFunction · 0.45
create_dgl_objectFunction · 0.45
batchFunction · 0.45
_gspmmFunction · 0.45
_gspmm_heteroFunction · 0.45

Calls 2

get_etype_idMethod · 0.95
sumFunction · 0.50

Tested by 15

test_parmetis_wrapperFunction · 0.36
_chunk_graphFunction · 0.36
_test_chunk_graphFunction · 0.36
test_redditFunction · 0.36
test_fakenewsFunction · 0.36
test_peptides_structuralFunction · 0.36
test_peptides_functionalFunction · 0.36
test_VOC_superpixelsFunction · 0.36
test_COCO_superpixelsFunction · 0.36
test_MNIST_SuperPixelFunction · 0.36
test_CIFAR10_SuperPixelFunction · 0.36
test_gat_convFunction · 0.36