dgl.DGLGraph.num_dst_nodes

DGLGraph.num_dst_nodes(ntype=None)[source]

Return the number of destination nodes in the graph.

If the graph can further divide its node types into two subsets A and B where all the edeges are from nodes of types in A to nodes of types in B, we call this graph a uni-bipartite graph and the nodes in A being the source nodes and the ones in B being the destination nodes. If the graph is not uni-bipartite, the source and destination nodes are just the entire set of nodes in the graph.

Parameters:

ntype (str, optional) – The destination node type name. If given, it returns the number of nodes of the destination node type. If not given (default), it returns the number of nodes summed over all the destination node types.

Returns:

The number of nodes

Return type:

int

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch

Create a homogeneous graph for query.

>>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2])))
>>> g.num_dst_nodes()
3

Create a heterogeneous graph with two destination node types – β€˜user’ and β€˜game’.

>>> g = dgl.heterograph({
...     ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
...     ('user', 'plays', 'game'): (torch.tensor([3, 4]), torch.tensor([5, 6]))
... })

Query for the number of nodes.

>>> g.num_dst_nodes('user')
5
>>> g.num_dst_nodes('game')
7
>>> g.num_dst_nodes()
12