code: def test_to_sparse_coo(dtype, device):
      kwargs = dict(dtype=dtype, device=device)
      adj = EdgeIndex([[1, 0, 2, 1], [0, 1, 1, 2]], **kwargs)
  
      if torch_geometric.typing.WITH_PT20:
          with pytest.raises(
              ValueError, match="Unexpected tensor layout"
          ):
              adj.to_sparse(layout="int64")
  
      if torch_geometric.typing.WITH_PT20:
          out = adj.to_sparse(layout=torch.sparse_coo)
      else:
          out = adj.to_sparse()
      assert isinstance(out, Tensor)
      assert out.dtype == torch.float
      assert out.device == device
      assert out.layout == torch.sparse_coo
      assert out.size() == (3, 3)
      assert adj.equal(out._indices())
      assert not out.is_coalesced()
  
      adj = EdgeIndex([[1, 0, 2, 1], [0, 1, 1, 2]], **kwargs)
      out = adj.to_sparse_coo()
      assert isinstance(out, Tensor)
      assert out.dtype == torch.float
      assert out.device == device
      assert out.layout == torch.sparse_coo
      assert out.size() == (3, 3)
      assert adj.equal(out._indices())
      assert not out.is_coalesced()
  
      adj = EdgeIndex(
          [[0, 1, 1, 2], [1, 0, 2, 1]], sort_order="row", **kwargs
      )
      out = adj.to_sparse_coo()
      assert isinstance(out, Tensor)
      assert out.dtype == torch.float
      assert out.device == device
      assert out.layout == torch.sparse_coo
      assert out.size() == (3, 3)
      assert adj.equal(out._indices())
      assert out.is_coalesced()
  
imports: import os.path
  import warnings
  from typing import List, Optional
  import pytest
  import torch
  from torch import Tensor, tensor
  import torch_geometric
  from torch_geometric import EdgeIndex
  from torch_geometric.edge_index import SUPPORTED_DTYPES, ReduceType, SortReturnType, _scatter_spmm, _torch_sparse_spmm, _TorchSPMM, set_tuple_item
  from torch_geometric.profile import benchmark
  from torch_geometric.testing import onlyCUDA, onlyLinux, withCUDA, withoutExtensions, withPackage
  from torch_geometric.typing import SparseTensor
  from torch_geometric.utils import scatter
label_desc: Use image node_id 20 for calling a global function with example usage: test_to_sparse_coo(dtype, device) without return types