dgl.DGLGraph.is_homogeneousΒΆ

property DGLGraph.is_homogeneousΒΆ

Return whether the graph is a homogeneous graph.

A homogeneous graph only has one node type and one edge type.

Returns

True if the graph is a homogeneous graph.

Return type

bool

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch

Create a homogeneous graph for check.

>>> g = dgl.graph((torch.tensor([0, 0, 1, 1]), torch.tensor([1, 0, 2, 3])))
>>> g.is_homogeneous
True

Create a heterogeneous graph for check.

If the graph has multiple edge types, one need to specify the edge type.

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