dgl.metapath_reachable_graph¶
-
dgl.
metapath_reachable_graph
(g, metapath)[source]¶ Return a graph where the successors of any node
u
are nodes reachable fromu
by the given metapath.If the beginning node type
s
and ending node typet
are the same, it will return a homogeneous graph with node types = t
. Otherwise, a unidirectional bipartite graph with source node types
and destination node typet
is returned.In both cases, two nodes
u
andv
will be connected with an edge(u, v)
if there exists one path matching the metapath fromu
tov
.The result graph keeps the node set of type
s
andt
in the original graph even if they might have no neighbor.The features of the source/destination node type in the original graph would be copied to the new graph.
- Parameters
- Returns
A homogeneous or unidirectional bipartite graph. It will be on CPU regardless of whether the input graph is on CPU or GPU.
- Return type
Notes
This function discards the batch information. Please use
dgl.DGLGraph.set_batch_num_nodes()
anddgl.DGLGraph.set_batch_num_edges()
on the transformed graph to maintain the information.Examples
>>> g = dgl.heterograph({ ... ('A', 'AB', 'B'): ([0, 1, 2], [1, 2, 3]), ... ('B', 'BA', 'A'): ([1, 2, 3], [0, 1, 2])}) >>> new_g = dgl.metapath_reachable_graph(g, ['AB', 'BA']) >>> new_g.edges(order='eid') (tensor([0, 1, 2]), tensor([0, 1, 2]))