dgl.DGLGraph.canonical_etypes

property DGLGraph.canonical_etypes

返回图中所有规范的边类型。

A canonical edge type is a string triplet (str, str, str) for source node type, edge type and destination node type.

Returns:

列表中的所有规范边类型三元组。

Return type:

list[(str, str, str)]

注释

DGL 内部为每种边类型分配一个整数 ID。返回的边类型名称根据其 ID 排序。

另请参阅

etypes

示例

以下示例使用PyTorch后端。

>>> import dgl
>>> import torch
>>> g = dgl.heterograph({
...     ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
...     ('user', 'follows', 'game'): (torch.tensor([0, 1, 2]), torch.tensor([1, 2, 3])),
...     ('user', 'plays', 'game'): (torch.tensor([1, 3]), torch.tensor([2, 3]))
... })
>>> g.canonical_etypes
[('user', 'follows', 'user'),
 ('user', 'follows', 'game'),
 ('user', 'plays', 'game')]