code: def rand_csr_uncoalesced(shape, nnz, dev):
      # Create a sparse matrix with possible duplicate entries.
      row = torch.randint(shape[0], (nnz,), device=dev)
      col = torch.randint(shape[1], (nnz,), device=dev)
      val = torch.randn(nnz, device=dev, requires_grad=True)
      indptr = torch.zeros(shape[0] + 1, device=dev, dtype=torch.int64)
      for r in row.tolist():
          indptr[r + 1] += 1
      indptr = torch.cumsum(indptr, 0)
      row_sorted, row_sorted_idx = torch.sort(row)
      indices = col[row_sorted_idx]
      indptr = rand_stride(indptr)
      indices = rand_stride(indices)
      val = rand_stride(val)
      return from_csr(indptr, indices, val, shape=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 8 for calling a global function with example usage: rand_csr_uncoalesced(shape, nnz, dev) and returns: from_csr