dgl.DGLGraph.is_multigraphΒΆ
-
property
DGLGraph.
is_multigraph
ΒΆ Return whether the graph is a multigraph with parallel edges.
A multigraph has more than one edges between the same pair of nodes, called parallel edges. For heterogeneous graphs, parallel edge further requires the canonical edge type to be the same (see
canonical_etypes()
for the definition).- Returns
True if the graph is a multigraph.
- Return type
Notes
Checking whether the graph is a multigraph could be expensive for a large one.
Examples
The following example uses PyTorch backend.
>>> import dgl >>> import torch
Check for homogeneous graphs.
>>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 3]))) >>> g.is_multigraph False >>> g = dgl.graph((torch.tensor([0, 1, 1]), torch.tensor([1, 3, 3]))) >>> g.is_multigraph True
Check for heterogeneous graphs.
>>> 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])) ... }) >>> g.is_multigraph False >>> g = dgl.heterograph({ ... ('user', 'follows', 'user'): (torch.tensor([0, 1, 1]), torch.tensor([1, 2, 2])), ... ('user', 'follows', 'game'): (torch.tensor([0, 1, 2]), torch.tensor([1, 2, 3])) ... }) >>> g.is_multigraph True