dgl.line_graph
- dgl.line_graph(g, backtracking=True, shared=False)[source]
返回此图的线图。
给定图
G
的线图L(G)
被定义为另一个图,其中L(G)
中的节点对应于G
中的边。对于G
中的任何一对边(u, v)
和(v, w)
,L(G)
中边(u, v)
对应的节点将有一条边连接到边(v, w)
对应的节点。- Parameters:
- Returns:
G – 该图的线图。
- Return type:
注释
如果
shared
为 True,则结果图的节点特征与输入图的边特征共享相同的存储。因此,用户应尽量避免对两个图都可见的原地操作。该函数支持在GPU上输入图形,但在计算期间会将其复制到CPU。
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.
示例
假设图具有以下邻接矩阵:
A = [[0, 0, 1], [1, 0, 1], [1, 1, 0]]
>>> g = dgl.graph(([0, 1, 1, 2, 2],[2, 0, 2, 0, 1]), 'user', 'follows') >>> lg = g.line_graph() >>> lg Graph(num_nodes=5, num_edges=8, ndata_schemes={} edata_schemes={}) >>> lg.edges() (tensor([0, 0, 1, 2, 2, 3, 4, 4]), tensor([3, 4, 0, 3, 4, 0, 1, 2])) >>> lg = g.line_graph(backtracking=False) >>> lg Graph(num_nodes=5, num_edges=4, ndata_schemes={} edata_schemes={}) >>> lg.edges() (tensor([0, 1, 2, 4]), tensor([4, 0, 3, 1]))