r"""Update the structure of a graph. Parameters ---------- g : DGLGraph The graph to update. data_dict : graph data The dictionary data for constructing a heterogeneous graph. copy_edata : bool If True, it will copy the edge features to the updated graph.
(g, data_dict, copy_edata=True)
| 58 | |
| 59 | |
| 60 | def update_graph_structure(g, data_dict, copy_edata=True): |
| 61 | r"""Update the structure of a graph. |
| 62 | |
| 63 | Parameters |
| 64 | ---------- |
| 65 | g : DGLGraph |
| 66 | The graph to update. |
| 67 | data_dict : graph data |
| 68 | The dictionary data for constructing a heterogeneous graph. |
| 69 | copy_edata : bool |
| 70 | If True, it will copy the edge features to the updated graph. |
| 71 | |
| 72 | Returns |
| 73 | ------- |
| 74 | DGLGraph |
| 75 | The updated graph. |
| 76 | """ |
| 77 | device = g.device |
| 78 | idtype = g.idtype |
| 79 | num_nodes_dict = dict() |
| 80 | |
| 81 | for ntype in g.ntypes: |
| 82 | num_nodes_dict[ntype] = g.num_nodes(ntype) |
| 83 | |
| 84 | new_g = convert.heterograph( |
| 85 | data_dict, num_nodes_dict=num_nodes_dict, idtype=idtype, device=device |
| 86 | ) |
| 87 | |
| 88 | # Copy features |
| 89 | for ntype in g.ntypes: |
| 90 | for key, feat in g.nodes[ntype].data.items(): |
| 91 | new_g.nodes[ntype].data[key] = feat |
| 92 | |
| 93 | if copy_edata: |
| 94 | for c_etype in g.canonical_etypes: |
| 95 | for key, feat in g.edges[c_etype].data.items(): |
| 96 | new_g.edges[c_etype].data[key] = feat |
| 97 | |
| 98 | return new_g |
| 99 | |
| 100 | |
| 101 | class BaseTransform: |