# dgl.to_homo¶

dgl.to_homo(G)[source]

Convert the given heterogeneous graph to a homogeneous graph.

The returned graph has only one type of nodes and edges.

Node and edge types are stored as features in the returned graph. Each feature is an integer representing the type id, which can be used to retrieve the type names stored in G.ntypes and G.etypes arguments.

Parameters: G (DGLHeteroGraph) – Input heterogeneous graph. A homogeneous graph. The parent node and edge type/ID are stored in columns dgl.NTYPE/dgl.NID and dgl.ETYPE/dgl.EID respectively. DGLHeteroGraph

Examples

>>> follows_g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
>>> devs_g = dgl.bipartite([(0, 0), (1, 1)], 'developer', 'develops', 'game')
>>> hetero_g = dgl.hetero_from_relations([follows_g, devs_g])
>>> homo_g = dgl.to_homo(hetero_g)
>>> homo_g.ndata
{'_TYPE': tensor([0, 0, 0, 1, 1, 2, 2]), '_ID': tensor([0, 1, 2, 0, 1, 0, 1])}
First three nodes for 'user', next two for 'developer' and the last two for 'game'
>>> homo_g.edata
{'_TYPE': tensor([0, 0, 1, 1]), '_ID': tensor([0, 1, 0, 1])}
First two edges for 'follows', next two for 'develops'