code: def rand_coo(shape, nnz, dev, nz_dim=None):
      # Create a sparse matrix without duplicate entries.
      nnzid = np.random.choice(shape[0] * shape[1], nnz, replace=False)
      nnzid = torch.tensor(nnzid, device=dev).long()
      row = torch.div(nnzid, shape[1], rounding_mode="floor")
      col = nnzid % shape[1]
      if nz_dim is None:
          val = torch.randn(nnz, device=dev, requires_grad=True)
      else:
          val = torch.randn(nnz, nz_dim, device=dev, requires_grad=True)
      indices = torch.stack([row, col])
      indices = rand_stride(indices)
      val = rand_stride(val)
      return spmatrix(indices, val, shape)
  
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 3 for calling a global function with example usage: rand_coo(shape, nnz, dev, nz_dim) and returns: spmatrix