dgl.DGLGraph.canonical_etypes

property DGLGraph.canonical_etypes

Return all the canonical edge types in the graph.

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

Returns

All the canonical edge type triplets in a list.

Return type

list[(str, str, str)]

Notes

DGL internally assigns an integer ID for each edge type. The returned edge type names are sorted according to their IDs.

See also

etypes

Examples

The following example uses PyTorch backend.

>>> 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')]