dgl.DGLGraph.create_formats_

DGLGraph.create_formats_()

Create all sparse matrices allowed for the graph.

By default, we create sparse matrices for a graph only when necessary. In some cases we may want to create them immediately (e.g. in a multi-process data loader), which can be achieved via this API.

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch

Homographs or Heterographs with A Single Edge Type

>>> 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': []}

Heterographs with Multiple Edge Types

>>> 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': []}