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

Method successors

python/dgl/heterograph.py:3089–3145  ·  view source on GitHub ↗

Return the successor(s) of a particular node with the specified edge type. Node ``u`` is a successor of node ``v`` if there is an edge ``(v, u)`` with type ``etype`` in the graph. Parameters ---------- v : int The node ID. If the graph has multip

(self, v, etype=None)

Source from the content-addressed store, hash-verified

3087 return self._graph.predecessors(self.get_etype_id(etype), v)
3088
3089 def successors(self, v, etype=None):
3090 """Return the successor(s) of a particular node with the specified edge type.
3091
3092 Node ``u`` is a successor of node ``v`` if there is an edge ``(v, u)`` with type
3093 ``etype`` in the graph.
3094
3095 Parameters
3096 ----------
3097 v : int
3098 The node ID. If the graph has multiple edge types, the ID is for the source
3099 type corresponding to the edge type.
3100 etype : str or (str, str, str), optional
3101 The type names of the edges. The allowed type name formats are:
3102
3103 * ``(str, str, str)`` for source node type, edge type and destination node type.
3104 * or one ``str`` edge type name if the name can uniquely identify a
3105 triplet format in the graph.
3106
3107 Can be omitted if the graph has only one type of edges.
3108
3109 Returns
3110 -------
3111 Tensor
3112 The successors of :attr:`v` with the specified edge type.
3113
3114 Examples
3115 --------
3116 The following example uses PyTorch backend.
3117
3118 >>> import dgl
3119 >>> import torch
3120
3121 Create a homogeneous graph.
3122
3123 >>> g = dgl.graph((torch.tensor([0, 0, 1, 1]), torch.tensor([1, 1, 2, 3])))
3124
3125 Query for node 1.
3126
3127 >>> g.successors(1)
3128 tensor([2, 3])
3129
3130 For a graph of multiple edge types, it is required to specify the edge type in query.
3131
3132 >>> hg = dgl.heterograph({
3133 ... ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
3134 ... ('user', 'plays', 'game'): (torch.tensor([3, 4]), torch.tensor([5, 6]))
3135 ... })
3136 >>> hg.successors(1, etype='follows')
3137 tensor([2])
3138
3139 See Also
3140 --------
3141 predecessors
3142 """
3143 if not self.has_nodes(v, self.to_canonical_etype(etype)[0]):
3144 raise DGLError("Non-existing node ID {}".format(v))
3145 return self._graph.successors(self.get_etype_id(etype), v)
3146

Callers 14

_testFunction · 0.45
_test_hypersparseFunction · 0.45
_test_queryFunction · 0.45
_test_oneFunction · 0.45
_test_csr_oneFunction · 0.45
test_reorder_nodesFunction · 0.45
_recover_nodeMethod · 0.45
_assemble_nodeMethod · 0.45
can_assembleFunction · 0.45
dfs_assembleMethod · 0.45
is_cycleFunction · 0.45
dglGraph_to_adj_listFunction · 0.45

Calls 5

has_nodesMethod · 0.95
to_canonical_etypeMethod · 0.95
get_etype_idMethod · 0.95
DGLErrorClass · 0.85
formatMethod · 0.80

Tested by 6

_testFunction · 0.36
_test_hypersparseFunction · 0.36
_test_queryFunction · 0.36
_test_oneFunction · 0.36
_test_csr_oneFunction · 0.36
test_reorder_nodesFunction · 0.36