code: def test_to_device(device):
      row = torch.tensor([1, 1, 2])
      col = torch.tensor([1, 2, 0])
      mat = from_coo(row, col, shape=(3, 4))
  
      target_row = row.to(device)
      target_col = col.to(device)
      target_val = mat.val.to(device)
  
      mat2 = mat.to(device=device)
      assert mat2.shape == mat.shape
      assert torch.allclose(mat2.row, target_row)
      assert torch.allclose(mat2.col, target_col)
      assert torch.allclose(mat2.val, target_val)
  
      mat2 = getattr(mat, device)()
      assert mat2.shape == mat.shape
      assert torch.allclose(mat2.row, target_row)
      assert torch.allclose(mat2.col, target_col)
      assert torch.allclose(mat2.val, target_val)
  
imports: import unittest
  import warnings
  import backend
  import pytest
  import torch
  from dgl.sparse import diag, from_coo, from_csc, from_csr, from_torch_sparse, identity, to_torch_sparse_coo, to_torch_sparse_csc, to_torch_sparse_csr, val_like
  from .utils import rand_coo, rand_csc, rand_csr, rand_diag, sparse_matrix_to_dense
label_desc: Use image node_id 22 for calling a global function with example usage: test_to_device(device) without return types