Load Graph from path and return a Graph in numpy. Args: path: The directory path of the stored Graph. mmap_mode: Default :code:`mmap_mode="r"`. If not None, memory-map the graph.
(cls, path, mmap_mode="r")
| 257 | |
| 258 | @classmethod |
| 259 | def load(cls, path, mmap_mode="r"): |
| 260 | """Load Graph from path and return a Graph in numpy. |
| 261 | |
| 262 | Args: |
| 263 | |
| 264 | path: The directory path of the stored Graph. |
| 265 | |
| 266 | mmap_mode: Default :code:`mmap_mode="r"`. If not None, memory-map the graph. |
| 267 | |
| 268 | """ |
| 269 | |
| 270 | num_nodes = np.load( |
| 271 | os.path.join(path, 'num_nodes.npy'), mmap_mode=mmap_mode) |
| 272 | edges = np.load(os.path.join(path, 'edges.npy'), mmap_mode=mmap_mode) |
| 273 | num_graph = np.load( |
| 274 | os.path.join(path, 'num_graph.npy'), mmap_mode=mmap_mode) |
| 275 | if os.path.exists(os.path.join(path, 'graph_node_index.npy')): |
| 276 | graph_node_index = np.load( |
| 277 | os.path.join(path, 'graph_node_index.npy'), |
| 278 | mmap_mode=mmap_mode) |
| 279 | else: |
| 280 | graph_node_index = None |
| 281 | |
| 282 | if os.path.exists(os.path.join(path, 'graph_edge_index.npy')): |
| 283 | graph_edge_index = np.load( |
| 284 | os.path.join(path, 'graph_edge_index.npy'), |
| 285 | mmap_mode=mmap_mode) |
| 286 | else: |
| 287 | graph_edge_index = None |
| 288 | |
| 289 | if os.path.isdir(os.path.join(path, 'adj_src')): |
| 290 | adj_src_index = EdgeIndex.load( |
| 291 | os.path.join(path, 'adj_src'), mmap_mode=mmap_mode) |
| 292 | else: |
| 293 | adj_src_index = None |
| 294 | |
| 295 | if os.path.isdir(os.path.join(path, 'adj_dst')): |
| 296 | adj_dst_index = EdgeIndex.load( |
| 297 | os.path.join(path, 'adj_dst'), mmap_mode=mmap_mode) |
| 298 | else: |
| 299 | adj_dst_index = None |
| 300 | |
| 301 | def _load_feat(feat_path): |
| 302 | """Load features from .npy file. |
| 303 | """ |
| 304 | feat = {} |
| 305 | if os.path.isdir(feat_path): |
| 306 | for feat_name in os.listdir(feat_path): |
| 307 | feat[os.path.splitext(feat_name)[0]] = np.load( |
| 308 | os.path.join(feat_path, feat_name), |
| 309 | mmap_mode=mmap_mode) |
| 310 | return feat |
| 311 | |
| 312 | node_feat = _load_feat(os.path.join(path, 'node_feat')) |
| 313 | edge_feat = _load_feat(os.path.join(path, 'edge_feat')) |
| 314 | return cls(edges=edges, |
| 315 | num_nodes=num_nodes, |
| 316 | node_feat=node_feat, |
no outgoing calls
no test coverage detected