dgl.DGLGraph.create_formats_
- DGLGraph.create_formats_()[source]
创建图允许的所有稀疏矩阵。
默认情况下,我们仅在必要时为图创建稀疏矩阵。 在某些情况下,我们可能希望立即创建它们(例如在多进程数据加载器中),这可以通过此API实现。
示例
以下示例使用PyTorch后端。
>>> import dgl >>> import torch
具有单一边缘类型的同形词或异形词
>>> g = dgl.graph(([0, 0, 1], [2, 3, 2])) >>> g.format() {'created': ['coo'], 'not created': ['csr', 'csc']} >>> g.create_formats_() >>> g.format() {'created': ['coo', 'csr', 'csc'], 'not created': []}
具有多种边类型的异构图
>>> g = dgl.heterograph({ ... ('user', 'plays', 'game'): (torch.tensor([0, 1, 1, 2]), ... torch.tensor([0, 0, 1, 1])), ... ('developer', 'develops', 'game'): (torch.tensor([0, 1]), ... torch.tensor([0, 1])) ... }) >>> g.format() {'created': ['coo'], 'not created': ['csr', 'csc']} >>> g.create_formats_() >>> g.format() {'created': ['coo', 'csr', 'csc'], 'not created': []}