code: def test_coalesce():
      ctx = F.ctx()
  
      row = torch.tensor([1, 0, 0, 0, 1]).to(ctx)
      col = torch.tensor([1, 1, 1, 2, 2]).to(ctx)
      val = torch.arange(len(row)).to(ctx)
      A = from_coo(row, col, val, (4, 4))
  
      assert A.has_duplicate()
  
      A_coalesced = A.coalesce()
  
      assert A_coalesced.nnz == 4
      assert A_coalesced.shape == (4, 4)
      assert list(A_coalesced.row) == [0, 0, 1, 1]
      assert list(A_coalesced.col) == [1, 2, 1, 2]
      # Values of duplicate indices are added together.
      assert list(A_coalesced.val) == [3, 3, 0, 4]
      assert not A_coalesced.has_duplicate()
  
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 15 for calling a global function with example usage: test_coalesce() without return types