Return the total number of nodes in the distributed graph. Parameters ---------- ntype : str, optional The node type name. If given, it returns the number of nodes of the type. If not given (default), it returns the total number of nodes of all types.
(self, ntype=None)
| 1161 | return self.num_edges(etype) |
| 1162 | |
| 1163 | def num_nodes(self, ntype=None): |
| 1164 | """Return the total number of nodes in the distributed graph. |
| 1165 | |
| 1166 | Parameters |
| 1167 | ---------- |
| 1168 | ntype : str, optional |
| 1169 | The node type name. If given, it returns the number of nodes of the |
| 1170 | type. If not given (default), it returns the total number of nodes of all types. |
| 1171 | |
| 1172 | Returns |
| 1173 | ------- |
| 1174 | int |
| 1175 | The number of nodes |
| 1176 | |
| 1177 | Examples |
| 1178 | -------- |
| 1179 | >>> g = dgl.distributed.DistGraph('ogb-product') |
| 1180 | >>> print(g.num_nodes()) |
| 1181 | 2449029 |
| 1182 | """ |
| 1183 | if ntype is None: |
| 1184 | if len(self.ntypes) == 1: |
| 1185 | return self._gpb._num_nodes(self.ntypes[0]) |
| 1186 | else: |
| 1187 | return sum( |
| 1188 | [self._gpb._num_nodes(ntype) for ntype in self.ntypes] |
| 1189 | ) |
| 1190 | return self._gpb._num_nodes(ntype) |
| 1191 | |
| 1192 | def num_edges(self, etype=None): |
| 1193 | """Return the total number of edges in the distributed graph. |