We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fail to import Nell dataset
### 🐛 Describe the bug

I tried to import Nell data set using NELL class:
from torch_geometric.datasets import NELL

dataset = NELL(root='data/Nell')
data = dataset[0]

But I got the following error message:
Traceback (most recent call last):
  File "c:\Users\13466\Desktop\USTLab\LabDoc\HPCA23\Nell.py", line 10, in <module>
    dataset = NELL(root='data/Nell')
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\datasets\nell.py", line 62, in __init__
    super().__init__(root, transform, pre_transform)
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\data\in_memory_dataset.py", line 57, in __init__
    super().__init__(root, transform, pre_transform, pre_filter, log)
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\data\dataset.py", line 97, in __init__
    self._process()
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\data\dataset.py", line 230, in _process
    self.process()
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\datasets\nell.py", line 82, in process
    data = read_planetoid_data(self.raw_dir, 'nell.0.001')
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\io\planetoid.py", line 53, in read_planetoid_data
    row, col, value = SparseTensor.from_dense(x).coo()
AttributeError: type object 'SparseTensor' has no attribute 'from_dense'



### Environment

* PyG version:2.3.1
* PyTorch version:2.0.1
* OS:Windows 11
* Python version:3.10
* CUDA/cuDNN version:
* How you installed PyTorch and PyG (`conda`, `pip`, source):pip
* Any other relevant information (*e.g.*, version of `torch-scatter`):


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torch_geometric/typing.py`
Content:
```
1 import warnings
2 from typing import Dict, List, Optional, Tuple, Union
3 
4 import numpy as np
5 import torch
6 from torch import Tensor
7 
8 WITH_PT2 = int(torch.__version__.split('.')[0]) >= 2
9 
10 try:
11     import pyg_lib  # noqa
12     WITH_PYG_LIB = True
13     WITH_GMM = WITH_PT2 and hasattr(pyg_lib.ops, 'grouped_matmul')
14     WITH_SAMPLED_OP = hasattr(pyg_lib.ops, 'sampled_add')
15     WITH_INDEX_SORT = hasattr(pyg_lib.ops, 'index_sort')
16 except (ImportError, OSError) as e:
17     if isinstance(e, OSError):
18         warnings.warn(f"An issue occurred while importing 'pyg-lib'. "
19                       f"Disabling its usage. Stacktrace: {e}")
20     pyg_lib = object
21     WITH_PYG_LIB = False
22     WITH_GMM = False
23     WITH_SAMPLED_OP = False
24     WITH_INDEX_SORT = False
25 
26 try:
27     import torch_scatter  # noqa
28     WITH_TORCH_SCATTER = True
29 except (ImportError, OSError) as e:
30     if isinstance(e, OSError):
31         warnings.warn(f"An issue occurred while importing 'torch-scatter'. "
32                       f"Disabling its usage. Stacktrace: {e}")
33     torch_scatter = object
34     WITH_TORCH_SCATTER = False
35 
36 try:
37     import torch_cluster  # noqa
38     WITH_TORCH_CLUSTER = True
39     WITH_TORCH_CLUSTER_BATCH_SIZE = 'batch_size' in torch_cluster.knn.__doc__
40 except (ImportError, OSError) as e:
41     if isinstance(e, OSError):
42         warnings.warn(f"An issue occurred while importing 'torch-cluster'. "
43                       f"Disabling its usage. Stacktrace: {e}")
44     WITH_TORCH_CLUSTER = False
45 
46 try:
47     import torch_spline_conv  # noqa
48     WITH_TORCH_SPLINE_CONV = True
49 except (ImportError, OSError) as e:
50     if isinstance(e, OSError):
51         warnings.warn(
52             f"An issue occurred while importing 'torch-spline-conv'. "
53             f"Disabling its usage. Stacktrace: {e}")
54     WITH_TORCH_SPLINE_CONV = False
55 
56 try:
57     import torch_sparse  # noqa
58     from torch_sparse import SparseStorage, SparseTensor
59     WITH_TORCH_SPARSE = True
60 except (ImportError, OSError) as e:
61     if isinstance(e, OSError):
62         warnings.warn(f"An issue occurred while importing 'torch-sparse'. "
63                       f"Disabling its usage. Stacktrace: {e}")
64     WITH_TORCH_SPARSE = False
65 
66     class SparseStorage:
67         def __init__(
68             self,
69             row: Optional[Tensor] = None,
70             rowptr: Optional[Tensor] = None,
71             col: Optional[Tensor] = None,
72             value: Optional[Tensor] = None,
73             sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,
74             rowcount: Optional[Tensor] = None,
75             colptr: Optional[Tensor] = None,
76             colcount: Optional[Tensor] = None,
77             csr2csc: Optional[Tensor] = None,
78             csc2csr: Optional[Tensor] = None,
79             is_sorted: bool = False,
80             trust_data: bool = False,
81         ):
82             raise ImportError("'SparseStorage' requires 'torch-sparse'")
83 
84     class SparseTensor:
85         def __init__(
86             self,
87             row: Optional[Tensor] = None,
88             rowptr: Optional[Tensor] = None,
89             col: Optional[Tensor] = None,
90             value: Optional[Tensor] = None,
91             sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,
92             is_sorted: bool = False,
93             trust_data: bool = False,
94         ):
95             raise ImportError("'SparseTensor' requires 'torch-sparse'")
96 
97         @classmethod
98         def from_edge_index(
99             self,
100             edge_index: Tensor,
101             edge_attr: Optional[Tensor] = None,
102             sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,
103             is_sorted: bool = False,
104             trust_data: bool = False,
105         ) -> 'SparseTensor':
106             raise ImportError("'SparseTensor' requires 'torch-sparse'")
107 
108         def size(self, dim: int) -> int:
109             raise ImportError("'SparseTensor' requires 'torch-sparse'")
110 
111         def is_cuda(self) -> bool:
112             raise ImportError("'SparseTensor' requires 'torch-sparse'")
113 
114         def has_value(self) -> bool:
115             raise ImportError("'SparseTensor' requires 'torch-sparse'")
116 
117         def set_value(self, value: Optional[Tensor],
118                       layout: Optional[str] = None) -> 'SparseTensor':
119             raise ImportError("'SparseTensor' requires 'torch-sparse'")
120 
121         def fill_value(self, fill_value: float,
122                        dtype: Optional[torch.dtype] = None) -> 'SparseTensor':
123             raise ImportError("'SparseTensor' requires 'torch-sparse'")
124 
125         def coo(self) -> Tuple[Tensor, Tensor, Optional[Tensor]]:
126             raise ImportError("'SparseTensor' requires 'torch-sparse'")
127 
128         def csr(self) -> Tuple[Tensor, Tensor, Optional[Tensor]]:
129             raise ImportError("'SparseTensor' requires 'torch-sparse'")
130 
131         def to_torch_sparse_csr_tensor(
132             self,
133             dtype: Optional[torch.dtype] = None,
134         ) -> Tensor:
135             raise ImportError("'SparseTensor' requires 'torch-sparse'")
136 
137     class torch_sparse:
138         @staticmethod
139         def matmul(src: SparseTensor, other: Tensor,
140                    reduce: str = "sum") -> Tensor:
141             raise ImportError("'matmul' requires 'torch-sparse'")
142 
143         @staticmethod
144         def sum(src: SparseTensor, dim: Optional[int] = None) -> Tensor:
145             raise ImportError("'sum' requires 'torch-sparse'")
146 
147         @staticmethod
148         def mul(src: SparseTensor, other: Tensor) -> SparseTensor:
149             raise ImportError("'mul' requires 'torch-sparse'")
150 
151         @staticmethod
152         def set_diag(src: SparseTensor, values: Optional[Tensor] = None,
153                      k: int = 0) -> SparseTensor:
154             raise ImportError("'set_diag' requires 'torch-sparse'")
155 
156         @staticmethod
157         def fill_diag(src: SparseTensor, fill_value: float,
158                       k: int = 0) -> SparseTensor:
159             raise ImportError("'fill_diag' requires 'torch-sparse'")
160 
161         @staticmethod
162         def masked_select_nnz(src: SparseTensor, mask: Tensor,
163                               layout: Optional[str] = None) -> SparseTensor:
164             raise ImportError("'masked_select_nnz' requires 'torch-sparse'")
165 
166 
167 # Types for accessing data ####################################################
168 
169 # Node-types are denoted by a single string, e.g.: `data['paper']`:
170 NodeType = str
171 
172 # Edge-types are denotes by a triplet of strings, e.g.:
173 # `data[('author', 'writes', 'paper')]
174 EdgeType = Tuple[str, str, str]
175 
176 DEFAULT_REL = 'to'
177 EDGE_TYPE_STR_SPLIT = '__'
178 
179 
180 class EdgeTypeStr(str):
181     r"""A helper class to construct serializable edge types by merging an edge
182     type tuple into a single string."""
183     def __new__(cls, *args):
184         if isinstance(args[0], (list, tuple)):
185             # Unwrap `EdgeType((src, rel, dst))` and `EdgeTypeStr((src, dst))`:
186             args = tuple(args[0])
187 
188         if len(args) == 1 and isinstance(args[0], str):
189             args = args[0]  # An edge type string was passed.
190 
191         elif len(args) == 2 and all(isinstance(arg, str) for arg in args):
192             # A `(src, dst)` edge type was passed - add `DEFAULT_REL`:
193             args = (args[0], DEFAULT_REL, args[1])
194             args = EDGE_TYPE_STR_SPLIT.join(args)
195 
196         elif len(args) == 3 and all(isinstance(arg, str) for arg in args):
197             # A `(src, rel, dst)` edge type was passed:
198             args = EDGE_TYPE_STR_SPLIT.join(args)
199 
200         else:
201             raise ValueError(f"Encountered invalid edge type '{args}'")
202 
203         return str.__new__(cls, args)
204 
205     def to_tuple(self) -> EdgeType:
206         r"""Returns the original edge type."""
207         out = tuple(self.split(EDGE_TYPE_STR_SPLIT))
208         if len(out) != 3:
209             raise ValueError(f"Cannot convert the edge type '{self}' to a "
210                              f"tuple since it holds invalid characters")
211         return out
212 
213 
214 # There exist some short-cuts to query edge-types (given that the full triplet
215 # can be uniquely reconstructed, e.g.:
216 # * via str: `data['writes']`
217 # * via Tuple[str, str]: `data[('author', 'paper')]`
218 QueryType = Union[NodeType, EdgeType, str, Tuple[str, str]]
219 
220 Metadata = Tuple[List[NodeType], List[EdgeType]]
221 
222 # A representation of a feature tensor
223 FeatureTensorType = Union[Tensor, np.ndarray]
224 
225 # A representation of an edge index, following the possible formats:
226 #   * COO: (row, col)
227 #   * CSC: (row, colptr)
228 #   * CSR: (rowptr, col)
229 EdgeTensorType = Tuple[Tensor, Tensor]
230 
231 # Types for message passing ###################################################
232 
233 Adj = Union[Tensor, SparseTensor]
234 OptTensor = Optional[Tensor]
235 PairTensor = Tuple[Tensor, Tensor]
236 OptPairTensor = Tuple[Tensor, Optional[Tensor]]
237 PairOptTensor = Tuple[Optional[Tensor], Optional[Tensor]]
238 Size = Optional[Tuple[int, int]]
239 NoneType = Optional[Tensor]
240 
241 MaybeHeteroNodeTensor = Union[Tensor, Dict[NodeType, Tensor]]
242 MaybeHeteroEdgeTensor = Union[Tensor, Dict[EdgeType, Tensor]]
243 
244 # Types for sampling ##########################################################
245 
246 InputNodes = Union[OptTensor, NodeType, Tuple[NodeType, OptTensor]]
247 InputEdges = Union[OptTensor, EdgeType, Tuple[EdgeType, OptTensor]]
248
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torch_geometric/typing.py b/torch_geometric/typing.py
--- a/torch_geometric/typing.py
+++ b/torch_geometric/typing.py
@@ -105,6 +105,11 @@
         ) -> 'SparseTensor':
             raise ImportError("'SparseTensor' requires 'torch-sparse'")
 
+        @classmethod
+        def from_dense(self, mat: Tensor,
+                       has_value: bool = True) -> 'SparseTensor':
+            raise ImportError("'SparseTensor' requires 'torch-sparse'")
+
         def size(self, dim: int) -> int:
             raise ImportError("'SparseTensor' requires 'torch-sparse'")

{"golden_diff": "diff --git a/torch_geometric/typing.py b/torch_geometric/typing.py\n--- a/torch_geometric/typing.py\n+++ b/torch_geometric/typing.py\n@@ -105,6 +105,11 @@\n         ) -> 'SparseTensor':\n             raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n \n+        @classmethod\n+        def from_dense(self, mat: Tensor,\n+                       has_value: bool = True) -> 'SparseTensor':\n+            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n+\n         def size(self, dim: int) -> int:\n             raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n", "issue": "Fail to import Nell dataset\n### \ud83d\udc1b Describe the bug\n\nI tried to import Nell data set using NELL class:\r\nfrom torch_geometric.datasets import NELL\r\n\r\ndataset = NELL(root='data/Nell')\r\ndata = dataset[0]\r\n\r\nBut I got the following error message:\r\nTraceback (most recent call last):\r\n  File \"c:\\Users\\13466\\Desktop\\USTLab\\LabDoc\\HPCA23\\Nell.py\", line 10, in <module>\r\n    dataset = NELL(root='data/Nell')\r\n  File \"C:\\Users\\13466\\anaconda3\\lib\\site-packages\\torch_geometric\\datasets\\nell.py\", line 62, in __init__\r\n    super().__init__(root, transform, pre_transform)\r\n  File \"C:\\Users\\13466\\anaconda3\\lib\\site-packages\\torch_geometric\\data\\in_memory_dataset.py\", line 57, in __init__\r\n    super().__init__(root, transform, pre_transform, pre_filter, log)\r\n  File \"C:\\Users\\13466\\anaconda3\\lib\\site-packages\\torch_geometric\\data\\dataset.py\", line 97, in __init__\r\n    self._process()\r\n  File \"C:\\Users\\13466\\anaconda3\\lib\\site-packages\\torch_geometric\\data\\dataset.py\", line 230, in _process\r\n    self.process()\r\n  File \"C:\\Users\\13466\\anaconda3\\lib\\site-packages\\torch_geometric\\datasets\\nell.py\", line 82, in process\r\n    data = read_planetoid_data(self.raw_dir, 'nell.0.001')\r\n  File \"C:\\Users\\13466\\anaconda3\\lib\\site-packages\\torch_geometric\\io\\planetoid.py\", line 53, in read_planetoid_data\r\n    row, col, value = SparseTensor.from_dense(x).coo()\r\nAttributeError: type object 'SparseTensor' has no attribute 'from_dense'\r\n\r\n\n\n### Environment\n\n* PyG version:2.3.1\r\n* PyTorch version:2.0.1\r\n* OS:Windows 11\r\n* Python version:3.10\r\n* CUDA/cuDNN version:\r\n* How you installed PyTorch and PyG (`conda`, `pip`, source):pip\r\n* Any other relevant information (*e.g.*, version of `torch-scatter`):\r\n\n", "before_files": [{"content": "import warnings\nfrom typing import Dict, List, Optional, Tuple, Union\n\nimport numpy as np\nimport torch\nfrom torch import Tensor\n\nWITH_PT2 = int(torch.__version__.split('.')[0]) >= 2\n\ntry:\n    import pyg_lib  # noqa\n    WITH_PYG_LIB = True\n    WITH_GMM = WITH_PT2 and hasattr(pyg_lib.ops, 'grouped_matmul')\n    WITH_SAMPLED_OP = hasattr(pyg_lib.ops, 'sampled_add')\n    WITH_INDEX_SORT = hasattr(pyg_lib.ops, 'index_sort')\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'pyg-lib'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    pyg_lib = object\n    WITH_PYG_LIB = False\n    WITH_GMM = False\n    WITH_SAMPLED_OP = False\n    WITH_INDEX_SORT = False\n\ntry:\n    import torch_scatter  # noqa\n    WITH_TORCH_SCATTER = True\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'torch-scatter'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    torch_scatter = object\n    WITH_TORCH_SCATTER = False\n\ntry:\n    import torch_cluster  # noqa\n    WITH_TORCH_CLUSTER = True\n    WITH_TORCH_CLUSTER_BATCH_SIZE = 'batch_size' in torch_cluster.knn.__doc__\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'torch-cluster'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    WITH_TORCH_CLUSTER = False\n\ntry:\n    import torch_spline_conv  # noqa\n    WITH_TORCH_SPLINE_CONV = True\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(\n            f\"An issue occurred while importing 'torch-spline-conv'. \"\n            f\"Disabling its usage. Stacktrace: {e}\")\n    WITH_TORCH_SPLINE_CONV = False\n\ntry:\n    import torch_sparse  # noqa\n    from torch_sparse import SparseStorage, SparseTensor\n    WITH_TORCH_SPARSE = True\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'torch-sparse'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    WITH_TORCH_SPARSE = False\n\n    class SparseStorage:\n        def __init__(\n            self,\n            row: Optional[Tensor] = None,\n            rowptr: Optional[Tensor] = None,\n            col: Optional[Tensor] = None,\n            value: Optional[Tensor] = None,\n            sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,\n            rowcount: Optional[Tensor] = None,\n            colptr: Optional[Tensor] = None,\n            colcount: Optional[Tensor] = None,\n            csr2csc: Optional[Tensor] = None,\n            csc2csr: Optional[Tensor] = None,\n            is_sorted: bool = False,\n            trust_data: bool = False,\n        ):\n            raise ImportError(\"'SparseStorage' requires 'torch-sparse'\")\n\n    class SparseTensor:\n        def __init__(\n            self,\n            row: Optional[Tensor] = None,\n            rowptr: Optional[Tensor] = None,\n            col: Optional[Tensor] = None,\n            value: Optional[Tensor] = None,\n            sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,\n            is_sorted: bool = False,\n            trust_data: bool = False,\n        ):\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        @classmethod\n        def from_edge_index(\n            self,\n            edge_index: Tensor,\n            edge_attr: Optional[Tensor] = None,\n            sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,\n            is_sorted: bool = False,\n            trust_data: bool = False,\n        ) -> 'SparseTensor':\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def size(self, dim: int) -> int:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def is_cuda(self) -> bool:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def has_value(self) -> bool:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def set_value(self, value: Optional[Tensor],\n                      layout: Optional[str] = None) -> 'SparseTensor':\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def fill_value(self, fill_value: float,\n                       dtype: Optional[torch.dtype] = None) -> 'SparseTensor':\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def coo(self) -> Tuple[Tensor, Tensor, Optional[Tensor]]:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def csr(self) -> Tuple[Tensor, Tensor, Optional[Tensor]]:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def to_torch_sparse_csr_tensor(\n            self,\n            dtype: Optional[torch.dtype] = None,\n        ) -> Tensor:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n    class torch_sparse:\n        @staticmethod\n        def matmul(src: SparseTensor, other: Tensor,\n                   reduce: str = \"sum\") -> Tensor:\n            raise ImportError(\"'matmul' requires 'torch-sparse'\")\n\n        @staticmethod\n        def sum(src: SparseTensor, dim: Optional[int] = None) -> Tensor:\n            raise ImportError(\"'sum' requires 'torch-sparse'\")\n\n        @staticmethod\n        def mul(src: SparseTensor, other: Tensor) -> SparseTensor:\n            raise ImportError(\"'mul' requires 'torch-sparse'\")\n\n        @staticmethod\n        def set_diag(src: SparseTensor, values: Optional[Tensor] = None,\n                     k: int = 0) -> SparseTensor:\n            raise ImportError(\"'set_diag' requires 'torch-sparse'\")\n\n        @staticmethod\n        def fill_diag(src: SparseTensor, fill_value: float,\n                      k: int = 0) -> SparseTensor:\n            raise ImportError(\"'fill_diag' requires 'torch-sparse'\")\n\n        @staticmethod\n        def masked_select_nnz(src: SparseTensor, mask: Tensor,\n                              layout: Optional[str] = None) -> SparseTensor:\n            raise ImportError(\"'masked_select_nnz' requires 'torch-sparse'\")\n\n\n# Types for accessing data ####################################################\n\n# Node-types are denoted by a single string, e.g.: `data['paper']`:\nNodeType = str\n\n# Edge-types are denotes by a triplet of strings, e.g.:\n# `data[('author', 'writes', 'paper')]\nEdgeType = Tuple[str, str, str]\n\nDEFAULT_REL = 'to'\nEDGE_TYPE_STR_SPLIT = '__'\n\n\nclass EdgeTypeStr(str):\n    r\"\"\"A helper class to construct serializable edge types by merging an edge\n    type tuple into a single string.\"\"\"\n    def __new__(cls, *args):\n        if isinstance(args[0], (list, tuple)):\n            # Unwrap `EdgeType((src, rel, dst))` and `EdgeTypeStr((src, dst))`:\n            args = tuple(args[0])\n\n        if len(args) == 1 and isinstance(args[0], str):\n            args = args[0]  # An edge type string was passed.\n\n        elif len(args) == 2 and all(isinstance(arg, str) for arg in args):\n            # A `(src, dst)` edge type was passed - add `DEFAULT_REL`:\n            args = (args[0], DEFAULT_REL, args[1])\n            args = EDGE_TYPE_STR_SPLIT.join(args)\n\n        elif len(args) == 3 and all(isinstance(arg, str) for arg in args):\n            # A `(src, rel, dst)` edge type was passed:\n            args = EDGE_TYPE_STR_SPLIT.join(args)\n\n        else:\n            raise ValueError(f\"Encountered invalid edge type '{args}'\")\n\n        return str.__new__(cls, args)\n\n    def to_tuple(self) -> EdgeType:\n        r\"\"\"Returns the original edge type.\"\"\"\n        out = tuple(self.split(EDGE_TYPE_STR_SPLIT))\n        if len(out) != 3:\n            raise ValueError(f\"Cannot convert the edge type '{self}' to a \"\n                             f\"tuple since it holds invalid characters\")\n        return out\n\n\n# There exist some short-cuts to query edge-types (given that the full triplet\n# can be uniquely reconstructed, e.g.:\n# * via str: `data['writes']`\n# * via Tuple[str, str]: `data[('author', 'paper')]`\nQueryType = Union[NodeType, EdgeType, str, Tuple[str, str]]\n\nMetadata = Tuple[List[NodeType], List[EdgeType]]\n\n# A representation of a feature tensor\nFeatureTensorType = Union[Tensor, np.ndarray]\n\n# A representation of an edge index, following the possible formats:\n#   * COO: (row, col)\n#   * CSC: (row, colptr)\n#   * CSR: (rowptr, col)\nEdgeTensorType = Tuple[Tensor, Tensor]\n\n# Types for message passing ###################################################\n\nAdj = Union[Tensor, SparseTensor]\nOptTensor = Optional[Tensor]\nPairTensor = Tuple[Tensor, Tensor]\nOptPairTensor = Tuple[Tensor, Optional[Tensor]]\nPairOptTensor = Tuple[Optional[Tensor], Optional[Tensor]]\nSize = Optional[Tuple[int, int]]\nNoneType = Optional[Tensor]\n\nMaybeHeteroNodeTensor = Union[Tensor, Dict[NodeType, Tensor]]\nMaybeHeteroEdgeTensor = Union[Tensor, Dict[EdgeType, Tensor]]\n\n# Types for sampling ##########################################################\n\nInputNodes = Union[OptTensor, NodeType, Tuple[NodeType, OptTensor]]\nInputEdges = Union[OptTensor, EdgeType, Tuple[EdgeType, OptTensor]]\n", "path": "torch_geometric/typing.py"}], "after_files": [{"content": "import warnings\nfrom typing import Dict, List, Optional, Tuple, Union\n\nimport numpy as np\nimport torch\nfrom torch import Tensor\n\nWITH_PT2 = int(torch.__version__.split('.')[0]) >= 2\n\ntry:\n    import pyg_lib  # noqa\n    WITH_PYG_LIB = True\n    WITH_GMM = WITH_PT2 and hasattr(pyg_lib.ops, 'grouped_matmul')\n    WITH_SAMPLED_OP = hasattr(pyg_lib.ops, 'sampled_add')\n    WITH_INDEX_SORT = hasattr(pyg_lib.ops, 'index_sort')\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'pyg-lib'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    pyg_lib = object\n    WITH_PYG_LIB = False\n    WITH_GMM = False\n    WITH_SAMPLED_OP = False\n    WITH_INDEX_SORT = False\n\ntry:\n    import torch_scatter  # noqa\n    WITH_TORCH_SCATTER = True\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'torch-scatter'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    torch_scatter = object\n    WITH_TORCH_SCATTER = False\n\ntry:\n    import torch_cluster  # noqa\n    WITH_TORCH_CLUSTER = True\n    WITH_TORCH_CLUSTER_BATCH_SIZE = 'batch_size' in torch_cluster.knn.__doc__\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'torch-cluster'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    WITH_TORCH_CLUSTER = False\n\ntry:\n    import torch_spline_conv  # noqa\n    WITH_TORCH_SPLINE_CONV = True\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(\n            f\"An issue occurred while importing 'torch-spline-conv'. \"\n            f\"Disabling its usage. Stacktrace: {e}\")\n    WITH_TORCH_SPLINE_CONV = False\n\ntry:\n    import torch_sparse  # noqa\n    from torch_sparse import SparseStorage, SparseTensor\n    WITH_TORCH_SPARSE = True\nexcept (ImportError, OSError) as e:\n    if isinstance(e, OSError):\n        warnings.warn(f\"An issue occurred while importing 'torch-sparse'. \"\n                      f\"Disabling its usage. Stacktrace: {e}\")\n    WITH_TORCH_SPARSE = False\n\n    class SparseStorage:\n        def __init__(\n            self,\n            row: Optional[Tensor] = None,\n            rowptr: Optional[Tensor] = None,\n            col: Optional[Tensor] = None,\n            value: Optional[Tensor] = None,\n            sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,\n            rowcount: Optional[Tensor] = None,\n            colptr: Optional[Tensor] = None,\n            colcount: Optional[Tensor] = None,\n            csr2csc: Optional[Tensor] = None,\n            csc2csr: Optional[Tensor] = None,\n            is_sorted: bool = False,\n            trust_data: bool = False,\n        ):\n            raise ImportError(\"'SparseStorage' requires 'torch-sparse'\")\n\n    class SparseTensor:\n        def __init__(\n            self,\n            row: Optional[Tensor] = None,\n            rowptr: Optional[Tensor] = None,\n            col: Optional[Tensor] = None,\n            value: Optional[Tensor] = None,\n            sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,\n            is_sorted: bool = False,\n            trust_data: bool = False,\n        ):\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        @classmethod\n        def from_edge_index(\n            self,\n            edge_index: Tensor,\n            edge_attr: Optional[Tensor] = None,\n            sparse_sizes: Optional[Tuple[Optional[int], Optional[int]]] = None,\n            is_sorted: bool = False,\n            trust_data: bool = False,\n        ) -> 'SparseTensor':\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        @classmethod\n        def from_dense(self, mat: Tensor,\n                       has_value: bool = True) -> 'SparseTensor':\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def size(self, dim: int) -> int:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def is_cuda(self) -> bool:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def has_value(self) -> bool:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def set_value(self, value: Optional[Tensor],\n                      layout: Optional[str] = None) -> 'SparseTensor':\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def fill_value(self, fill_value: float,\n                       dtype: Optional[torch.dtype] = None) -> 'SparseTensor':\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def coo(self) -> Tuple[Tensor, Tensor, Optional[Tensor]]:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def csr(self) -> Tuple[Tensor, Tensor, Optional[Tensor]]:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n        def to_torch_sparse_csr_tensor(\n            self,\n            dtype: Optional[torch.dtype] = None,\n        ) -> Tensor:\n            raise ImportError(\"'SparseTensor' requires 'torch-sparse'\")\n\n    class torch_sparse:\n        @staticmethod\n        def matmul(src: SparseTensor, other: Tensor,\n                   reduce: str = \"sum\") -> Tensor:\n            raise ImportError(\"'matmul' requires 'torch-sparse'\")\n\n        @staticmethod\n        def sum(src: SparseTensor, dim: Optional[int] = None) -> Tensor:\n            raise ImportError(\"'sum' requires 'torch-sparse'\")\n\n        @staticmethod\n        def mul(src: SparseTensor, other: Tensor) -> SparseTensor:\n            raise ImportError(\"'mul' requires 'torch-sparse'\")\n\n        @staticmethod\n        def set_diag(src: SparseTensor, values: Optional[Tensor] = None,\n                     k: int = 0) -> SparseTensor:\n            raise ImportError(\"'set_diag' requires 'torch-sparse'\")\n\n        @staticmethod\n        def fill_diag(src: SparseTensor, fill_value: float,\n                      k: int = 0) -> SparseTensor:\n            raise ImportError(\"'fill_diag' requires 'torch-sparse'\")\n\n        @staticmethod\n        def masked_select_nnz(src: SparseTensor, mask: Tensor,\n                              layout: Optional[str] = None) -> SparseTensor:\n            raise ImportError(\"'masked_select_nnz' requires 'torch-sparse'\")\n\n\n# Types for accessing data ####################################################\n\n# Node-types are denoted by a single string, e.g.: `data['paper']`:\nNodeType = str\n\n# Edge-types are denotes by a triplet of strings, e.g.:\n# `data[('author', 'writes', 'paper')]\nEdgeType = Tuple[str, str, str]\n\nDEFAULT_REL = 'to'\nEDGE_TYPE_STR_SPLIT = '__'\n\n\nclass EdgeTypeStr(str):\n    r\"\"\"A helper class to construct serializable edge types by merging an edge\n    type tuple into a single string.\"\"\"\n    def __new__(cls, *args):\n        if isinstance(args[0], (list, tuple)):\n            # Unwrap `EdgeType((src, rel, dst))` and `EdgeTypeStr((src, dst))`:\n            args = tuple(args[0])\n\n        if len(args) == 1 and isinstance(args[0], str):\n            args = args[0]  # An edge type string was passed.\n\n        elif len(args) == 2 and all(isinstance(arg, str) for arg in args):\n            # A `(src, dst)` edge type was passed - add `DEFAULT_REL`:\n            args = (args[0], DEFAULT_REL, args[1])\n            args = EDGE_TYPE_STR_SPLIT.join(args)\n\n        elif len(args) == 3 and all(isinstance(arg, str) for arg in args):\n            # A `(src, rel, dst)` edge type was passed:\n            args = EDGE_TYPE_STR_SPLIT.join(args)\n\n        else:\n            raise ValueError(f\"Encountered invalid edge type '{args}'\")\n\n        return str.__new__(cls, args)\n\n    def to_tuple(self) -> EdgeType:\n        r\"\"\"Returns the original edge type.\"\"\"\n        out = tuple(self.split(EDGE_TYPE_STR_SPLIT))\n        if len(out) != 3:\n            raise ValueError(f\"Cannot convert the edge type '{self}' to a \"\n                             f\"tuple since it holds invalid characters\")\n        return out\n\n\n# There exist some short-cuts to query edge-types (given that the full triplet\n# can be uniquely reconstructed, e.g.:\n# * via str: `data['writes']`\n# * via Tuple[str, str]: `data[('author', 'paper')]`\nQueryType = Union[NodeType, EdgeType, str, Tuple[str, str]]\n\nMetadata = Tuple[List[NodeType], List[EdgeType]]\n\n# A representation of a feature tensor\nFeatureTensorType = Union[Tensor, np.ndarray]\n\n# A representation of an edge index, following the possible formats:\n#   * COO: (row, col)\n#   * CSC: (row, colptr)\n#   * CSR: (rowptr, col)\nEdgeTensorType = Tuple[Tensor, Tensor]\n\n# Types for message passing ###################################################\n\nAdj = Union[Tensor, SparseTensor]\nOptTensor = Optional[Tensor]\nPairTensor = Tuple[Tensor, Tensor]\nOptPairTensor = Tuple[Tensor, Optional[Tensor]]\nPairOptTensor = Tuple[Optional[Tensor], Optional[Tensor]]\nSize = Optional[Tuple[int, int]]\nNoneType = Optional[Tensor]\n\nMaybeHeteroNodeTensor = Union[Tensor, Dict[NodeType, Tensor]]\nMaybeHeteroEdgeTensor = Union[Tensor, Dict[EdgeType, Tensor]]\n\n# Types for sampling ##########################################################\n\nInputNodes = Union[OptTensor, NodeType, Tuple[NodeType, OptTensor]]\nInputEdges = Union[OptTensor, EdgeType, Tuple[EdgeType, OptTensor]]\n", "path": "torch_geometric/typing.py"}]}