code: def rand_diag(shape, nnz, dev, nz_dim=None):
      nnz = min(shape)
      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)
      return diag(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 6 for calling a global function with example usage: rand_diag(shape, nnz, dev, nz_dim) and returns: diag