r"""Get a cloned graph with the specified allowed sparse format(s) or query for the usage status of sparse formats. The API copies both the graph structure and the features. If the input graph has multiple edge types, they will have the same sparse format.
(self, formats=None)
| 6088 | self._edge_frames = old_eframes |
| 6089 | |
| 6090 | def formats(self, formats=None): |
| 6091 | r"""Get a cloned graph with the specified allowed sparse format(s) or |
| 6092 | query for the usage status of sparse formats. |
| 6093 | |
| 6094 | The API copies both the graph structure and the features. |
| 6095 | |
| 6096 | If the input graph has multiple edge types, they will have the same |
| 6097 | sparse format. |
| 6098 | |
| 6099 | When ``formats`` is not None, if the intersection between `formats` and |
| 6100 | the current graph's created sparse format(s) is not empty, the returned |
| 6101 | cloned graph only retains all sparse format(s) in the intersection. If |
| 6102 | the intersection is empty, a sparse format will be selected to be |
| 6103 | created following the order of ``'coo' -> 'csr' -> 'csc'``. |
| 6104 | |
| 6105 | Parameters |
| 6106 | ---------- |
| 6107 | formats : str or list of str or None |
| 6108 | |
| 6109 | * If formats is None, return the usage status of sparse formats |
| 6110 | * Otherwise, it can be ``'coo'``/``'csr'``/``'csc'`` or a sublist of |
| 6111 | them, specifying the sparse formats to use. |
| 6112 | |
| 6113 | Returns |
| 6114 | ------- |
| 6115 | dict or DGLGraph |
| 6116 | |
| 6117 | * If formats is None, the result will be a dict recording the usage |
| 6118 | status of sparse formats. |
| 6119 | * Otherwise, a DGLGraph will be returned, which is a clone of the |
| 6120 | original graph with the specified allowed sparse format(s) |
| 6121 | ``formats``. |
| 6122 | |
| 6123 | Examples |
| 6124 | -------- |
| 6125 | |
| 6126 | The following example uses PyTorch backend. |
| 6127 | |
| 6128 | >>> import dgl |
| 6129 | >>> import torch |
| 6130 | |
| 6131 | **Homographs or Heterographs with A Single Edge Type** |
| 6132 | |
| 6133 | >>> g = dgl.graph(([0, 0, 1], [2, 3, 2])) |
| 6134 | >>> g.ndata['h'] = torch.ones(4, 1) |
| 6135 | >>> # Check status of format usage. |
| 6136 | >>> g.formats() |
| 6137 | {'created': ['coo'], 'not created': ['csr', 'csc']} |
| 6138 | >>> # Get a clone of the graph with 'csr' format. |
| 6139 | >>> csr_g = g.formats('csr') |
| 6140 | >>> # Only allowed formats will be displayed in the status query. |
| 6141 | >>> csr_g.formats() |
| 6142 | {'created': ['csr'], 'not created': []} |
| 6143 | >>> # Features are copied as well. |
| 6144 | >>> csr_g.ndata['h'] |
| 6145 | tensor([[1.], |
| 6146 | [1.], |
| 6147 | [1.], |
no outgoing calls