code: def sparse_matrix_to_torch_sparse(A: SparseMatrix, val=None):
      row, col = A.coo()
      edge_index = torch.cat((row.unsqueeze(0), col.unsqueeze(0)), 0)
      shape = A.shape
      if val is None:
          val = A.val
      val = val.clone().detach()
      if len(A.val.shape) > 1:
          shape += (A.val.shape[-1],)
      ret = torch.sparse_coo_tensor(edge_index, val, shape).coalesce()
      ret.requires_grad_()
      return ret
  
file_path: dgl/tests/python/pytorch/sparse/utils.py
imports: import numpy
  import torch
  from dgl.sparse import diag, from_csc, from_csr, SparseMatrix, spmatrix
label_desc: Use image node_id 11 for calling a global function with example usage: sparse_matrix_to_torch_sparse(A, val) and returns: ret