dgl.DGLGraph.batch_size¶
-
property
DGLGraph.
batch_size
¶ Return the number of graphs in the batched graph.
- Returns
The Number of graphs in the batch. If the graph is not a batched one, it will return 1.
- Return type
Examples
The following example uses PyTorch backend.
>>> import dgl >>> import torch
Query for homogeneous graphs.
>>> g1 = dgl.graph((torch.tensor([0, 1, 2]), torch.tensor([1, 2, 3]))) >>> g1.batch_size 1 >>> g2 = dgl.graph((torch.tensor([0, 0, 0, 1]), torch.tensor([0, 1, 2, 0]))) >>> bg = dgl.batch([g1, g2]) >>> bg.batch_size 2
Query for heterogeneous graphs.
>>> hg1 = dgl.heterograph({ ... ('user', 'plays', 'game') : (torch.tensor([0, 1]), torch.tensor([0, 0]))}) >>> hg1.batch_size 1 >>> hg2 = dgl.heterograph({ ... ('user', 'plays', 'game') : (torch.tensor([0, 0]), torch.tensor([1, 0]))}) >>> bg = dgl.batch([hg1, hg2]) >>> bg.batch_size 2