dgl.DGLGraph.batch_size

property DGLGraph.batch_size

返回批处理图中的图的数量。

Returns:

批次中的图的数量。如果图不是批次的,它将返回1。

Return type:

int

示例

以下示例使用PyTorch后端。

>>> import dgl
>>> import torch

查询同构图。

>>> 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

查询异构图。

>>> 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