Return the out-degree(s) of the given nodes. It computes the out-degree(s). It does not support heterogeneous graphs yet. Parameters ---------- u : node IDs The node IDs. The allowed formats are: * ``int``: A single node.
(self, u=ALL)
| 1225 | return self._gpb._num_edges(etype) |
| 1226 | |
| 1227 | def out_degrees(self, u=ALL): |
| 1228 | """Return the out-degree(s) of the given nodes. |
| 1229 | |
| 1230 | It computes the out-degree(s). |
| 1231 | It does not support heterogeneous graphs yet. |
| 1232 | |
| 1233 | Parameters |
| 1234 | ---------- |
| 1235 | u : node IDs |
| 1236 | The node IDs. The allowed formats are: |
| 1237 | |
| 1238 | * ``int``: A single node. |
| 1239 | * Int Tensor: Each element is a node ID. The tensor must have the same device type |
| 1240 | and ID data type as the graph's. |
| 1241 | * iterable[int]: Each element is a node ID. |
| 1242 | |
| 1243 | If not given, return the in-degrees of all the nodes. |
| 1244 | |
| 1245 | Returns |
| 1246 | ------- |
| 1247 | int or Tensor |
| 1248 | The out-degree(s) of the node(s) in a Tensor. The i-th element is the out-degree |
| 1249 | of the i-th input node. If :attr:`v` is an ``int``, return an ``int`` too. |
| 1250 | |
| 1251 | Examples |
| 1252 | -------- |
| 1253 | The following example uses PyTorch backend. |
| 1254 | |
| 1255 | >>> import dgl |
| 1256 | >>> import torch |
| 1257 | |
| 1258 | Query for all nodes. |
| 1259 | |
| 1260 | >>> g.out_degrees() |
| 1261 | tensor([2, 2, 0, 0]) |
| 1262 | |
| 1263 | Query for nodes 1 and 2. |
| 1264 | |
| 1265 | >>> g.out_degrees(torch.tensor([1, 2])) |
| 1266 | tensor([2, 0]) |
| 1267 | |
| 1268 | See Also |
| 1269 | -------- |
| 1270 | in_degrees |
| 1271 | """ |
| 1272 | if is_all(u): |
| 1273 | u = F.arange(0, self.num_nodes()) |
| 1274 | return dist_out_degrees(self, u) |
| 1275 | |
| 1276 | def in_degrees(self, v=ALL): |
| 1277 | """Return the in-degree(s) of the given nodes. |