Convert a message flow graph (MFG) as a :class:`DGLBlock` object to a :class:`DGLGraph`. DGL will rename all the source node types by suffixing with ``_src``, and all the destination node types by suffixing with ``_dst``. Features on the returned graph will be preserved. Parameter
(block)
| 624 | |
| 625 | |
| 626 | def block_to_graph(block): |
| 627 | """Convert a message flow graph (MFG) as a :class:`DGLBlock` object to a :class:`DGLGraph`. |
| 628 | |
| 629 | DGL will rename all the source node types by suffixing with ``_src``, and |
| 630 | all the destination node types by suffixing with ``_dst``. |
| 631 | |
| 632 | Features on the returned graph will be preserved. |
| 633 | |
| 634 | Parameters |
| 635 | ---------- |
| 636 | block : DGLBlock |
| 637 | The MFG. |
| 638 | |
| 639 | Returns |
| 640 | ------- |
| 641 | DGLGraph |
| 642 | The graph. |
| 643 | |
| 644 | Examples |
| 645 | -------- |
| 646 | >>> block = dgl.create_block({ |
| 647 | ... ('A', 'AB', 'B'): ([1, 2, 3], [2, 1, 0]), |
| 648 | ... ('B', 'BA', 'A'): ([2, 1], [2, 3])}) |
| 649 | >>> g = dgl.block_to_graph(block) |
| 650 | >>> g |
| 651 | Graph(num_nodes={'A_src': 4, 'B_src': 3, 'A_dst': 4, 'B_dst': 3}, |
| 652 | num_edges={('A_src', 'AB', 'B_dst'): 3, ('B_src', 'BA', 'A_dst'): 2}, |
| 653 | metagraph=[('A_src', 'B_dst', 'AB'), ('B_src', 'A_dst', 'BA')]) |
| 654 | """ |
| 655 | new_types = [ntype + "_src" for ntype in block.srctypes] + [ |
| 656 | ntype + "_dst" for ntype in block.dsttypes |
| 657 | ] |
| 658 | retg = DGLGraph(block._graph, new_types, block.etypes) |
| 659 | |
| 660 | for srctype in block.srctypes: |
| 661 | retg.nodes[srctype + "_src"].data.update(block.srcnodes[srctype].data) |
| 662 | for dsttype in block.dsttypes: |
| 663 | retg.nodes[dsttype + "_dst"].data.update(block.dstnodes[dsttype].data) |
| 664 | for srctype, etype, dsttype in block.canonical_etypes: |
| 665 | retg.edges[srctype + "_src", etype, dsttype + "_dst"].data.update( |
| 666 | block.edges[srctype, etype, dsttype].data |
| 667 | ) |
| 668 | |
| 669 | return retg |
| 670 | |
| 671 | |
| 672 | def to_heterogeneous( |