dgl.DGLGraph.long
- DGLGraph.long()[source]
将图转换为具有idtype int64的图
如果图已经有idtype int64,函数直接返回它。否则,它返回一个idtype int64的克隆图,并复制特征(浅拷贝)。
- Returns:
idtype int64 的图表。
- Return type:
示例
以下示例使用PyTorch后端。
>>> import dgl >>> import torch
创建一个idtype为int32的图形。
>>> # (0, 1), (0, 2), (1, 2) >>> g = dgl.graph((torch.tensor([0, 0, 1]).int(), torch.tensor([1, 2, 2]).int())) >>> g.ndata['feat'] = torch.ones(3, 1) >>> g.idtype torch.int32
将图转换为idtype为int64的类型。
>>> # A cloned graph with an idtype of int64 >>> g_long = g.long() >>> g_long.idtype torch.int64 >>> # The idtype of the original graph does not change. >>> g.idtype torch.int32 >>> g_long.edges() (tensor([0, 0, 1]), tensor([1, 2, 2])) >>> g_long.ndata {'feat': tensor([[1.], [1.], [1.]])}