We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
I can't run dgl/examples/pytorch/han/train_sampling.py with cuda
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

## To Reproduce

Steps to reproduce the behavior:

1. I just run dgl/examples/pytorch/han/train_sampling.py with cuda, it has an error

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->
<img width="1103" alt="image" src="https://user-images.githubusercontent.com/53086386/156488968-32cde64a-1c14-4de7-93de-211ca4dd306e.png">


## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - DGL Version: 0.8.0+cu11.1
 - Backend Library & Version:  PyTorch0.9.1
 - OS: Linux
 - How you installed DGL: pip
 - Build command you used (if compiling from source):
 - Python version: 3.7.4
 - CUDA/cuDNN version: cuda11.1
 - GPU models and configuration: A100
 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/dgl/utils/checks.py`
Content:
```
1 """Checking and logging utilities."""
2 # pylint: disable=invalid-name
3 from __future__ import absolute_import, division
4 from collections.abc import Mapping
5 
6 from ..base import DGLError
7 from .._ffi.function import _init_api
8 from .. import backend as F
9 
10 def prepare_tensor(g, data, name):
11     """Convert the data to ID tensor and check its ID type and context.
12 
13     If the data is already in tensor type, raise error if its ID type
14     and context does not match the graph's.
15     Otherwise, convert it to tensor type of the graph's ID type and
16     ctx and return.
17 
18     Parameters
19     ----------
20     g : DGLHeteroGraph
21         Graph.
22     data : int, iterable of int, tensor
23         Data.
24     name : str
25         Name of the data.
26 
27     Returns
28     -------
29     Tensor
30         Data in tensor object.
31     """
32     if F.is_tensor(data):
33         if not g.is_pinned() and (F.dtype(data) != g.idtype or F.context(data) != g.device):
34             raise DGLError('Expect argument "{}" to have data type {} and device '
35                            'context {}. But got {} and {}.'.format(
36                                name, g.idtype, g.device, F.dtype(data), F.context(data)))
37         ret = data
38     else:
39         data = F.tensor(data)
40         if (not (F.ndim(data) > 0 and F.shape(data)[0] == 0) and        # empty tensor
41                 F.dtype(data) not in (F.int32, F.int64)):
42             raise DGLError('Expect argument "{}" to have data type int32 or int64,'
43                            ' but got {}.'.format(name, F.dtype(data)))
44         ret = F.copy_to(F.astype(data, g.idtype), g.device)
45 
46     if F.ndim(ret) == 0:
47         ret = F.unsqueeze(ret, 0)
48     if F.ndim(ret) > 1:
49         raise DGLError('Expect a 1-D tensor for argument "{}". But got {}.'.format(
50             name, ret))
51     return ret
52 
53 def prepare_tensor_dict(g, data, name):
54     """Convert a dictionary of data to a dictionary of ID tensors.
55 
56     Calls ``prepare_tensor`` on each key-value pair.
57 
58     Parameters
59     ----------
60     g : DGLHeteroGraph
61         Graph.
62     data : dict[str, (int, iterable of int, tensor)]
63         Data dict.
64     name : str
65         Name of the data.
66 
67     Returns
68     -------
69     dict[str, tensor]
70     """
71     return {key : prepare_tensor(g, val, '{}["{}"]'.format(name, key))
72             for key, val in data.items()}
73 
74 def prepare_tensor_or_dict(g, data, name):
75     """Convert data to either a tensor or a dictionary depending on input type.
76 
77     Parameters
78     ----------
79     g : DGLHeteroGraph
80         Graph.
81     data : dict[str, (int, iterable of int, tensor)]
82         Data dict.
83     name : str
84         Name of the data.
85 
86     Returns
87     -------
88     tensor or dict[str, tensor]
89     """
90     return prepare_tensor_dict(g, data, name) if isinstance(data, Mapping) \
91             else prepare_tensor(g, data, name)
92 
93 def parse_edges_arg_to_eid(g, edges, etid, argname='edges'):
94     """Parse the :attr:`edges` argument and return an edge ID tensor.
95 
96     The resulting edge ID tensor has the same ID type and device of :attr:`g`.
97 
98     Parameters
99     ----------
100     g : DGLGraph
101         Graph
102     edges : pair of Tensor, Tensor, iterable[int]
103         Argument for specifying edges.
104     etid : int
105         Edge type ID.
106     argname : str, optional
107         Argument name.
108 
109     Returns
110     -------
111     Tensor
112         Edge ID tensor
113     """
114     if isinstance(edges, tuple):
115         u, v = edges
116         u = prepare_tensor(g, u, '{}[0]'.format(argname))
117         v = prepare_tensor(g, v, '{}[1]'.format(argname))
118         eid = g.edge_ids(u, v, etype=g.canonical_etypes[etid])
119     else:
120         eid = prepare_tensor(g, edges, argname)
121     return eid
122 
123 def check_all_same_idtype(glist, name):
124     """Check all the graphs have the same idtype."""
125     if len(glist) == 0:
126         return
127     idtype = glist[0].idtype
128     for i, g in enumerate(glist):
129         if g.idtype != idtype:
130             raise DGLError('Expect {}[{}] to have {} type ID, but got {}.'.format(
131                 name, i, idtype, g.idtype))
132 
133 def check_device(data, device):
134     """Check if data is on the target device.
135 
136     Parameters
137     ----------
138     data : Tensor or dict[str, Tensor]
139     device: Backend device.
140 
141     Returns
142     -------
143     Bool: True if the data is on the target device.
144     """
145     if isinstance(data, dict):
146         for v in data.values():
147             if v.device != device:
148                 return False
149     elif data.device != device:
150         return False
151     return True
152 
153 def check_all_same_device(glist, name):
154     """Check all the graphs have the same device."""
155     if len(glist) == 0:
156         return
157     device = glist[0].device
158     for i, g in enumerate(glist):
159         if g.device != device:
160             raise DGLError('Expect {}[{}] to be on device {}, but got {}.'.format(
161                 name, i, device, g.device))
162 
163 def check_all_same_schema(schemas, name):
164     """Check the list of schemas are the same."""
165     if len(schemas) == 0:
166         return
167 
168     for i, schema in enumerate(schemas):
169         if schema != schemas[0]:
170             raise DGLError(
171                 'Expect all graphs to have the same schema on {}, '
172                 'but graph {} got\n\t{}\nwhich is different from\n\t{}.'.format(
173                     name, i, schema, schemas[0]))
174 
175 def check_all_same_schema_for_keys(schemas, keys, name):
176     """Check the list of schemas are the same on the given keys."""
177     if len(schemas) == 0:
178         return
179 
180     head = None
181     keys = set(keys)
182     for i, schema in enumerate(schemas):
183         if not keys.issubset(schema.keys()):
184             raise DGLError(
185                 'Expect all graphs to have keys {} on {}, '
186                 'but graph {} got keys {}.'.format(
187                     keys, name, i, schema.keys()))
188 
189         if head is None:
190             head = {k: schema[k] for k in keys}
191         else:
192             target = {k: schema[k] for k in keys}
193             if target != head:
194                 raise DGLError(
195                     'Expect all graphs to have the same schema for keys {} on {}, '
196                     'but graph {} got \n\t{}\n which is different from\n\t{}.'.format(
197                         keys, name, i, target, head))
198 
199 def check_valid_idtype(idtype):
200     """Check whether the value of the idtype argument is valid (int32/int64)
201 
202     Parameters
203     ----------
204     idtype : data type
205         The framework object of a data type.
206     """
207     if idtype not in [None, F.int32, F.int64]:
208         raise DGLError('Expect idtype to be a framework object of int32/int64, '
209                        'got {}'.format(idtype))
210 
211 def is_sorted_srcdst(src, dst, num_src=None, num_dst=None):
212     """Checks whether an edge list is in ascending src-major order (e.g., first
213     sorted by ``src`` and then by ``dst``).
214 
215     Parameters
216     ----------
217     src : IdArray
218         The tensor of source nodes for each edge.
219     dst : IdArray
220         The tensor of destination nodes for each edge.
221     num_src : int, optional
222         The number of source nodes.
223     num_dst : int, optional
224         The number of destination nodes.
225 
226     Returns
227     -------
228     bool, bool
229         Whether ``src`` is in ascending order, and whether ``dst`` is
230         in ascending order with respect to ``src``.
231     """
232     # for some versions of MXNET and TensorFlow, num_src and num_dst get
233     # incorrectly marked as floats, so force them as integers here
234     if num_src is None:
235         num_src = int(F.as_scalar(F.max(src, dim=0)+1))
236     if num_dst is None:
237         num_dst = int(F.as_scalar(F.max(dst, dim=0)+1))
238 
239     src = F.zerocopy_to_dgl_ndarray(src)
240     dst = F.zerocopy_to_dgl_ndarray(dst)
241     sorted_status = _CAPI_DGLCOOIsSorted(src, dst, num_src, num_dst)
242 
243     row_sorted = sorted_status > 0
244     col_sorted = sorted_status > 1
245 
246     return row_sorted, col_sorted
247 
248 _init_api("dgl.utils.checks")
249
```
--- 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/python/dgl/utils/checks.py b/python/dgl/utils/checks.py
--- a/python/dgl/utils/checks.py
+++ b/python/dgl/utils/checks.py
@@ -30,7 +30,7 @@
         Data in tensor object.
     """
     if F.is_tensor(data):
-        if not g.is_pinned() and (F.dtype(data) != g.idtype or F.context(data) != g.device):
+        if (F.dtype(data) != g.idtype or F.context(data) != g.device) and not g.is_pinned():
             raise DGLError('Expect argument "{}" to have data type {} and device '
                            'context {}. But got {} and {}.'.format(
                                name, g.idtype, g.device, F.dtype(data), F.context(data)))

{"golden_diff": "diff --git a/python/dgl/utils/checks.py b/python/dgl/utils/checks.py\n--- a/python/dgl/utils/checks.py\n+++ b/python/dgl/utils/checks.py\n@@ -30,7 +30,7 @@\n         Data in tensor object.\n     \"\"\"\n     if F.is_tensor(data):\n-        if not g.is_pinned() and (F.dtype(data) != g.idtype or F.context(data) != g.device):\n+        if (F.dtype(data) != g.idtype or F.context(data) != g.device) and not g.is_pinned():\n             raise DGLError('Expect argument \"{}\" to have data type {} and device '\n                            'context {}. But got {} and {}.'.format(\n                                name, g.idtype, g.device, F.dtype(data), F.context(data)))\n", "issue": "I can't run dgl/examples/pytorch/han/train_sampling.py with cuda\n## \ud83d\udc1b Bug\r\n\r\n<!-- A clear and concise description of what the bug is. -->\r\n\r\n## To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\n1. I just run dgl/examples/pytorch/han/train_sampling.py with cuda, it has an error\r\n\r\n<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->\r\n<img width=\"1103\" alt=\"image\" src=\"https://user-images.githubusercontent.com/53086386/156488968-32cde64a-1c14-4de7-93de-211ca4dd306e.png\">\r\n\r\n\r\n## Expected behavior\r\n\r\n<!-- A clear and concise description of what you expected to happen. -->\r\n\r\n## Environment\r\n\r\n - DGL Version: 0.8.0+cu11.1\r\n - Backend Library & Version:  PyTorch0.9.1\r\n - OS: Linux\r\n - How you installed DGL: pip\r\n - Build command you used (if compiling from source):\r\n - Python version: 3.7.4\r\n - CUDA/cuDNN version: cuda11.1\r\n - GPU models and configuration: A100\r\n - Any other relevant information:\r\n\r\n## Additional context\r\n\r\n<!-- Add any other context about the problem here. -->\r\n\n", "before_files": [{"content": "\"\"\"Checking and logging utilities.\"\"\"\n# pylint: disable=invalid-name\nfrom __future__ import absolute_import, division\nfrom collections.abc import Mapping\n\nfrom ..base import DGLError\nfrom .._ffi.function import _init_api\nfrom .. import backend as F\n\ndef prepare_tensor(g, data, name):\n    \"\"\"Convert the data to ID tensor and check its ID type and context.\n\n    If the data is already in tensor type, raise error if its ID type\n    and context does not match the graph's.\n    Otherwise, convert it to tensor type of the graph's ID type and\n    ctx and return.\n\n    Parameters\n    ----------\n    g : DGLHeteroGraph\n        Graph.\n    data : int, iterable of int, tensor\n        Data.\n    name : str\n        Name of the data.\n\n    Returns\n    -------\n    Tensor\n        Data in tensor object.\n    \"\"\"\n    if F.is_tensor(data):\n        if not g.is_pinned() and (F.dtype(data) != g.idtype or F.context(data) != g.device):\n            raise DGLError('Expect argument \"{}\" to have data type {} and device '\n                           'context {}. But got {} and {}.'.format(\n                               name, g.idtype, g.device, F.dtype(data), F.context(data)))\n        ret = data\n    else:\n        data = F.tensor(data)\n        if (not (F.ndim(data) > 0 and F.shape(data)[0] == 0) and        # empty tensor\n                F.dtype(data) not in (F.int32, F.int64)):\n            raise DGLError('Expect argument \"{}\" to have data type int32 or int64,'\n                           ' but got {}.'.format(name, F.dtype(data)))\n        ret = F.copy_to(F.astype(data, g.idtype), g.device)\n\n    if F.ndim(ret) == 0:\n        ret = F.unsqueeze(ret, 0)\n    if F.ndim(ret) > 1:\n        raise DGLError('Expect a 1-D tensor for argument \"{}\". But got {}.'.format(\n            name, ret))\n    return ret\n\ndef prepare_tensor_dict(g, data, name):\n    \"\"\"Convert a dictionary of data to a dictionary of ID tensors.\n\n    Calls ``prepare_tensor`` on each key-value pair.\n\n    Parameters\n    ----------\n    g : DGLHeteroGraph\n        Graph.\n    data : dict[str, (int, iterable of int, tensor)]\n        Data dict.\n    name : str\n        Name of the data.\n\n    Returns\n    -------\n    dict[str, tensor]\n    \"\"\"\n    return {key : prepare_tensor(g, val, '{}[\"{}\"]'.format(name, key))\n            for key, val in data.items()}\n\ndef prepare_tensor_or_dict(g, data, name):\n    \"\"\"Convert data to either a tensor or a dictionary depending on input type.\n\n    Parameters\n    ----------\n    g : DGLHeteroGraph\n        Graph.\n    data : dict[str, (int, iterable of int, tensor)]\n        Data dict.\n    name : str\n        Name of the data.\n\n    Returns\n    -------\n    tensor or dict[str, tensor]\n    \"\"\"\n    return prepare_tensor_dict(g, data, name) if isinstance(data, Mapping) \\\n            else prepare_tensor(g, data, name)\n\ndef parse_edges_arg_to_eid(g, edges, etid, argname='edges'):\n    \"\"\"Parse the :attr:`edges` argument and return an edge ID tensor.\n\n    The resulting edge ID tensor has the same ID type and device of :attr:`g`.\n\n    Parameters\n    ----------\n    g : DGLGraph\n        Graph\n    edges : pair of Tensor, Tensor, iterable[int]\n        Argument for specifying edges.\n    etid : int\n        Edge type ID.\n    argname : str, optional\n        Argument name.\n\n    Returns\n    -------\n    Tensor\n        Edge ID tensor\n    \"\"\"\n    if isinstance(edges, tuple):\n        u, v = edges\n        u = prepare_tensor(g, u, '{}[0]'.format(argname))\n        v = prepare_tensor(g, v, '{}[1]'.format(argname))\n        eid = g.edge_ids(u, v, etype=g.canonical_etypes[etid])\n    else:\n        eid = prepare_tensor(g, edges, argname)\n    return eid\n\ndef check_all_same_idtype(glist, name):\n    \"\"\"Check all the graphs have the same idtype.\"\"\"\n    if len(glist) == 0:\n        return\n    idtype = glist[0].idtype\n    for i, g in enumerate(glist):\n        if g.idtype != idtype:\n            raise DGLError('Expect {}[{}] to have {} type ID, but got {}.'.format(\n                name, i, idtype, g.idtype))\n\ndef check_device(data, device):\n    \"\"\"Check if data is on the target device.\n\n    Parameters\n    ----------\n    data : Tensor or dict[str, Tensor]\n    device: Backend device.\n\n    Returns\n    -------\n    Bool: True if the data is on the target device.\n    \"\"\"\n    if isinstance(data, dict):\n        for v in data.values():\n            if v.device != device:\n                return False\n    elif data.device != device:\n        return False\n    return True\n\ndef check_all_same_device(glist, name):\n    \"\"\"Check all the graphs have the same device.\"\"\"\n    if len(glist) == 0:\n        return\n    device = glist[0].device\n    for i, g in enumerate(glist):\n        if g.device != device:\n            raise DGLError('Expect {}[{}] to be on device {}, but got {}.'.format(\n                name, i, device, g.device))\n\ndef check_all_same_schema(schemas, name):\n    \"\"\"Check the list of schemas are the same.\"\"\"\n    if len(schemas) == 0:\n        return\n\n    for i, schema in enumerate(schemas):\n        if schema != schemas[0]:\n            raise DGLError(\n                'Expect all graphs to have the same schema on {}, '\n                'but graph {} got\\n\\t{}\\nwhich is different from\\n\\t{}.'.format(\n                    name, i, schema, schemas[0]))\n\ndef check_all_same_schema_for_keys(schemas, keys, name):\n    \"\"\"Check the list of schemas are the same on the given keys.\"\"\"\n    if len(schemas) == 0:\n        return\n\n    head = None\n    keys = set(keys)\n    for i, schema in enumerate(schemas):\n        if not keys.issubset(schema.keys()):\n            raise DGLError(\n                'Expect all graphs to have keys {} on {}, '\n                'but graph {} got keys {}.'.format(\n                    keys, name, i, schema.keys()))\n\n        if head is None:\n            head = {k: schema[k] for k in keys}\n        else:\n            target = {k: schema[k] for k in keys}\n            if target != head:\n                raise DGLError(\n                    'Expect all graphs to have the same schema for keys {} on {}, '\n                    'but graph {} got \\n\\t{}\\n which is different from\\n\\t{}.'.format(\n                        keys, name, i, target, head))\n\ndef check_valid_idtype(idtype):\n    \"\"\"Check whether the value of the idtype argument is valid (int32/int64)\n\n    Parameters\n    ----------\n    idtype : data type\n        The framework object of a data type.\n    \"\"\"\n    if idtype not in [None, F.int32, F.int64]:\n        raise DGLError('Expect idtype to be a framework object of int32/int64, '\n                       'got {}'.format(idtype))\n\ndef is_sorted_srcdst(src, dst, num_src=None, num_dst=None):\n    \"\"\"Checks whether an edge list is in ascending src-major order (e.g., first\n    sorted by ``src`` and then by ``dst``).\n\n    Parameters\n    ----------\n    src : IdArray\n        The tensor of source nodes for each edge.\n    dst : IdArray\n        The tensor of destination nodes for each edge.\n    num_src : int, optional\n        The number of source nodes.\n    num_dst : int, optional\n        The number of destination nodes.\n\n    Returns\n    -------\n    bool, bool\n        Whether ``src`` is in ascending order, and whether ``dst`` is\n        in ascending order with respect to ``src``.\n    \"\"\"\n    # for some versions of MXNET and TensorFlow, num_src and num_dst get\n    # incorrectly marked as floats, so force them as integers here\n    if num_src is None:\n        num_src = int(F.as_scalar(F.max(src, dim=0)+1))\n    if num_dst is None:\n        num_dst = int(F.as_scalar(F.max(dst, dim=0)+1))\n\n    src = F.zerocopy_to_dgl_ndarray(src)\n    dst = F.zerocopy_to_dgl_ndarray(dst)\n    sorted_status = _CAPI_DGLCOOIsSorted(src, dst, num_src, num_dst)\n\n    row_sorted = sorted_status > 0\n    col_sorted = sorted_status > 1\n\n    return row_sorted, col_sorted\n\n_init_api(\"dgl.utils.checks\")\n", "path": "python/dgl/utils/checks.py"}], "after_files": [{"content": "\"\"\"Checking and logging utilities.\"\"\"\n# pylint: disable=invalid-name\nfrom __future__ import absolute_import, division\nfrom collections.abc import Mapping\n\nfrom ..base import DGLError\nfrom .._ffi.function import _init_api\nfrom .. import backend as F\n\ndef prepare_tensor(g, data, name):\n    \"\"\"Convert the data to ID tensor and check its ID type and context.\n\n    If the data is already in tensor type, raise error if its ID type\n    and context does not match the graph's.\n    Otherwise, convert it to tensor type of the graph's ID type and\n    ctx and return.\n\n    Parameters\n    ----------\n    g : DGLHeteroGraph\n        Graph.\n    data : int, iterable of int, tensor\n        Data.\n    name : str\n        Name of the data.\n\n    Returns\n    -------\n    Tensor\n        Data in tensor object.\n    \"\"\"\n    if F.is_tensor(data):\n        if (F.dtype(data) != g.idtype or F.context(data) != g.device) and not g.is_pinned():\n            raise DGLError('Expect argument \"{}\" to have data type {} and device '\n                           'context {}. But got {} and {}.'.format(\n                               name, g.idtype, g.device, F.dtype(data), F.context(data)))\n        ret = data\n    else:\n        data = F.tensor(data)\n        if (not (F.ndim(data) > 0 and F.shape(data)[0] == 0) and        # empty tensor\n                F.dtype(data) not in (F.int32, F.int64)):\n            raise DGLError('Expect argument \"{}\" to have data type int32 or int64,'\n                           ' but got {}.'.format(name, F.dtype(data)))\n        ret = F.copy_to(F.astype(data, g.idtype), g.device)\n\n    if F.ndim(ret) == 0:\n        ret = F.unsqueeze(ret, 0)\n    if F.ndim(ret) > 1:\n        raise DGLError('Expect a 1-D tensor for argument \"{}\". But got {}.'.format(\n            name, ret))\n    return ret\n\ndef prepare_tensor_dict(g, data, name):\n    \"\"\"Convert a dictionary of data to a dictionary of ID tensors.\n\n    Calls ``prepare_tensor`` on each key-value pair.\n\n    Parameters\n    ----------\n    g : DGLHeteroGraph\n        Graph.\n    data : dict[str, (int, iterable of int, tensor)]\n        Data dict.\n    name : str\n        Name of the data.\n\n    Returns\n    -------\n    dict[str, tensor]\n    \"\"\"\n    return {key : prepare_tensor(g, val, '{}[\"{}\"]'.format(name, key))\n            for key, val in data.items()}\n\ndef prepare_tensor_or_dict(g, data, name):\n    \"\"\"Convert data to either a tensor or a dictionary depending on input type.\n\n    Parameters\n    ----------\n    g : DGLHeteroGraph\n        Graph.\n    data : dict[str, (int, iterable of int, tensor)]\n        Data dict.\n    name : str\n        Name of the data.\n\n    Returns\n    -------\n    tensor or dict[str, tensor]\n    \"\"\"\n    return prepare_tensor_dict(g, data, name) if isinstance(data, Mapping) \\\n            else prepare_tensor(g, data, name)\n\ndef parse_edges_arg_to_eid(g, edges, etid, argname='edges'):\n    \"\"\"Parse the :attr:`edges` argument and return an edge ID tensor.\n\n    The resulting edge ID tensor has the same ID type and device of :attr:`g`.\n\n    Parameters\n    ----------\n    g : DGLGraph\n        Graph\n    edges : pair of Tensor, Tensor, iterable[int]\n        Argument for specifying edges.\n    etid : int\n        Edge type ID.\n    argname : str, optional\n        Argument name.\n\n    Returns\n    -------\n    Tensor\n        Edge ID tensor\n    \"\"\"\n    if isinstance(edges, tuple):\n        u, v = edges\n        u = prepare_tensor(g, u, '{}[0]'.format(argname))\n        v = prepare_tensor(g, v, '{}[1]'.format(argname))\n        eid = g.edge_ids(u, v, etype=g.canonical_etypes[etid])\n    else:\n        eid = prepare_tensor(g, edges, argname)\n    return eid\n\ndef check_all_same_idtype(glist, name):\n    \"\"\"Check all the graphs have the same idtype.\"\"\"\n    if len(glist) == 0:\n        return\n    idtype = glist[0].idtype\n    for i, g in enumerate(glist):\n        if g.idtype != idtype:\n            raise DGLError('Expect {}[{}] to have {} type ID, but got {}.'.format(\n                name, i, idtype, g.idtype))\n\ndef check_device(data, device):\n    \"\"\"Check if data is on the target device.\n\n    Parameters\n    ----------\n    data : Tensor or dict[str, Tensor]\n    device: Backend device.\n\n    Returns\n    -------\n    Bool: True if the data is on the target device.\n    \"\"\"\n    if isinstance(data, dict):\n        for v in data.values():\n            if v.device != device:\n                return False\n    elif data.device != device:\n        return False\n    return True\n\ndef check_all_same_device(glist, name):\n    \"\"\"Check all the graphs have the same device.\"\"\"\n    if len(glist) == 0:\n        return\n    device = glist[0].device\n    for i, g in enumerate(glist):\n        if g.device != device:\n            raise DGLError('Expect {}[{}] to be on device {}, but got {}.'.format(\n                name, i, device, g.device))\n\ndef check_all_same_schema(schemas, name):\n    \"\"\"Check the list of schemas are the same.\"\"\"\n    if len(schemas) == 0:\n        return\n\n    for i, schema in enumerate(schemas):\n        if schema != schemas[0]:\n            raise DGLError(\n                'Expect all graphs to have the same schema on {}, '\n                'but graph {} got\\n\\t{}\\nwhich is different from\\n\\t{}.'.format(\n                    name, i, schema, schemas[0]))\n\ndef check_all_same_schema_for_keys(schemas, keys, name):\n    \"\"\"Check the list of schemas are the same on the given keys.\"\"\"\n    if len(schemas) == 0:\n        return\n\n    head = None\n    keys = set(keys)\n    for i, schema in enumerate(schemas):\n        if not keys.issubset(schema.keys()):\n            raise DGLError(\n                'Expect all graphs to have keys {} on {}, '\n                'but graph {} got keys {}.'.format(\n                    keys, name, i, schema.keys()))\n\n        if head is None:\n            head = {k: schema[k] for k in keys}\n        else:\n            target = {k: schema[k] for k in keys}\n            if target != head:\n                raise DGLError(\n                    'Expect all graphs to have the same schema for keys {} on {}, '\n                    'but graph {} got \\n\\t{}\\n which is different from\\n\\t{}.'.format(\n                        keys, name, i, target, head))\n\ndef check_valid_idtype(idtype):\n    \"\"\"Check whether the value of the idtype argument is valid (int32/int64)\n\n    Parameters\n    ----------\n    idtype : data type\n        The framework object of a data type.\n    \"\"\"\n    if idtype not in [None, F.int32, F.int64]:\n        raise DGLError('Expect idtype to be a framework object of int32/int64, '\n                       'got {}'.format(idtype))\n\ndef is_sorted_srcdst(src, dst, num_src=None, num_dst=None):\n    \"\"\"Checks whether an edge list is in ascending src-major order (e.g., first\n    sorted by ``src`` and then by ``dst``).\n\n    Parameters\n    ----------\n    src : IdArray\n        The tensor of source nodes for each edge.\n    dst : IdArray\n        The tensor of destination nodes for each edge.\n    num_src : int, optional\n        The number of source nodes.\n    num_dst : int, optional\n        The number of destination nodes.\n\n    Returns\n    -------\n    bool, bool\n        Whether ``src`` is in ascending order, and whether ``dst`` is\n        in ascending order with respect to ``src``.\n    \"\"\"\n    # for some versions of MXNET and TensorFlow, num_src and num_dst get\n    # incorrectly marked as floats, so force them as integers here\n    if num_src is None:\n        num_src = int(F.as_scalar(F.max(src, dim=0)+1))\n    if num_dst is None:\n        num_dst = int(F.as_scalar(F.max(dst, dim=0)+1))\n\n    src = F.zerocopy_to_dgl_ndarray(src)\n    dst = F.zerocopy_to_dgl_ndarray(dst)\n    sorted_status = _CAPI_DGLCOOIsSorted(src, dst, num_src, num_dst)\n\n    row_sorted = sorted_status > 0\n    col_sorted = sorted_status > 1\n\n    return row_sorted, col_sorted\n\n_init_api(\"dgl.utils.checks\")\n", "path": "python/dgl/utils/checks.py"}]}