dgl.DGLGraph.to_canonical_etype
- DGLGraph.to_canonical_etype(etype)[source]
将图中的边类型转换为对应的规范边类型。
规范边类型是用于源节点类型、边类型和目标节点类型的字符串三元组
(str, str, str)
。该函数期望给定的边类型名称能唯一标识一个规范边类型。如果不是这种情况,DGL 将引发错误。
- 参数:
etype (str 或 (str, str, str)) – 如果
etype
是一个边类型 (str),它返回图中对应的规范边类型。如果etype
已经是规范边类型,则直接返回输入,不做更改。- 返回:
与边类型对应的规范边类型。
- 返回类型:
示例
以下示例使用 PyTorch 后端。
>>> import dgl >>> import torch
创建一个异构图。
>>> g = dgl.heterograph({ ... ('user', 'follows', 'user'): ([0, 1], [1, 2]), ... ('user', 'plays', 'game'): ([0, 1, 1, 2], [0, 0, 1, 1]), ... ('developer', 'follows', 'game'): ([0, 1], [0, 1]) ... })
将边类型映射到其对应的规范边类型。
>>> g.to_canonical_etype('plays') ('user', 'plays', 'game') >>> g.to_canonical_etype(('user', 'plays', 'game')) ('user', 'plays', 'game')
另请参阅