code: def random_sparse_conv2d_params(
      func, params, bs_r, bs_c, density, layout
  ):
      """Replace the dense parameters with random sparse parameters. Mainly used for testing.
  
      Parameters
      ----------
      func : tvm.relay.Expr
          Expr will be optimized to sparse operation.
      params : Dict[Srting, tvm.nd.array]
          Parameters of the Expr.
      bs_r : int
          The row of BSR matrix block.
      bs_c : int
          The column of BSR matrix block.
      density : float
          The density of the random sparse parameters.
      layout : str
          layout of network
  
      Returns
      -------
      Dict[Srting, tvm.nd.array]
          The generated random parameters.
      """
      # pylint: disable=import-outside-toplevel
      import numpy as np
  
      def deepcopy(param_dic):
          ret = {}
          for k, v in param_dic.items():
              ret[k] = tvm.nd.array(v.numpy())
          return ret
  
      new_params = deepcopy(params)
      conv2d_weight_names = (
          relay.analysis.sparse_conv2d._search_conv2d_op_weight(func)
      )
      for item in conv2d_weight_names:
          name = str(item)
          shape = new_params[name].shape
          if not (
              (shape[0] == 1 and shape[1] == 1)
              or (shape[2] == 1 and shape[3] == 1)
          ):
              continue
          if (
              layout == "NCHW"
              and shape[0] % bs_r == 0
              and shape[1] % bs_c == 0
          ):
              new_w = random_bsr_matrix(
                  shape[0], shape[1], bs_r, bs_c, density, "float32"
              ).todense()
              new_params[name] = tvm.nd.array(
                  np.array(new_w).reshape(shape)
              )
          elif (
              layout == "NHWC"
              and shape[3] % bs_r == 0
              and shape[2] % bs_c == 0
          ):
              new_w = random_bsr_matrix(
                  shape[3], shape[2], bs_r, bs_c, density, "float32"
              ).todense()
              new_params[name] = tvm.nd.array(
                  np.array(new_w).reshape(shape)
              )
      return new_params
  
file_path: tvm/python/tvm/topi/sparse/utils.py
imports: import tvm
  from tvm import relay, auto_scheduler
  from tvm.relay import data_dep_optimization
  from tvm.auto_scheduler import _ffi_api
label_desc: Use image node_id 3 for calling a global function with example usage: random_sparse_conv2d_params(func, params, bs_r, bs_c, density, layout) and returns: new_params, ret