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)
| 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 |