code: def _cov_sparse(x, return_gram=False, return_mean=False):
      """
      Computes the mean and the covariance of matrix X of
      the form Cov(X, X) = E(XX) - E(X)E(X)
  
      This is a temporary fix for
      cuml issue #5475 and cupy issue #7699,
      where the operation `x.T.dot(x)` did not work for
      larger sparse matrices.
  
      Parameters
      ----------
  
      x : cupyx.scipy.sparse of size (m, n)
      return_gram : boolean (default = False)
          If True, gram matrix of the form (1 / n) * X.T.dot(X)
          will be returned.
          When True, a copy will be created
          to store the results of the covariance.
          When False, the local gram matrix result
          will be overwritten
      return_mean: boolean (default = False)
          If True, the Maximum Likelihood Estimate used to
          calculate the mean of X and X will be returned,
          of the form (1 / n) * mean(X) and (1 / n) * mean(X)
  
      Returns
      -------
  
      result : cov(X, X) when return_gram and return_mean are False
              cov(X, X), gram(X, X) when return_gram is True,
              return_mean is False
              cov(X, X), mean(X), mean(X) when return_gram is False,
              return_mean is True
              cov(X, X), gram(X, X), mean(X), mean(X)
              when return_gram is True and return_mean is True
      """
  
      gram_matrix = cp.zeros(
          (x.shape[1], x.shape[1]), dtype=x.data.dtype
      )
      if cupyx.scipy.sparse.isspmatrix_csr(x):
          block = (128,)
          grid = (x.shape[0],)
          compute_mean_cov = _gramm_kernel_csr(x.data.dtype)
          compute_mean_cov(
              grid,
              block,
              (
                  x.indptr,
                  x.indices,
                  x.data,
                  x.shape[0],
                  x.shape[1],
                  gram_matrix,
              ),
          )
  
      elif cupyx.scipy.sparse.isspmatrix_coo(x):
          x.sum_duplicates()
          nnz = len(x.row)
          block = (128,)
          grid = (nnz,)
          compute_gram_coo = _gramm_kernel_coo(x.data.dtype)
          compute_gram_coo(
              grid,
              block,
              (
                  x.row,
                  x.col,
                  x.data,
                  nnz,
                  x.shape[1],
                  x.shape[0],
                  gram_matrix,
              ),
          )
  
      else:
          x = x.tocsr()
          block = (128,)
          grid = (math.ceil(x.shape[0] / block[0]),)
          compute_mean_cov = _gramm_kernel_csr(x.data.dtype)
          compute_mean_cov(
              grid,
              block,
              (
                  x.indptr,
                  x.indices,
                  x.data,
                  x.shape[0],
                  x.shape[1],
                  gram_matrix,
              ),
          )
  
      copy_gram = _copy_kernel(x.data.dtype)
      block = (32, 32)
      grid = (
          math.ceil(x.shape[1] / block[0]),
          math.ceil(x.shape[1] / block[1]),
      )
      copy_gram(
          grid,
          block,
          (gram_matrix, x.shape[1]),
      )
  
      mean_x = x.sum(axis=0) * (1 / x.shape[0])
      gram_matrix *= 1 / x.shape[0]
  
      if return_gram:
          cov_result = cp.zeros(
              (gram_matrix.shape[0], gram_matrix.shape[0]),
              dtype=gram_matrix.dtype,
          )
      else:
          cov_result = gram_matrix
  
      compute_cov = _cov_kernel(x.dtype)
  
      block_size = (32, 32)
      grid_size = (math.ceil(gram_matrix.shape[0] / 8),) * 2
      compute_cov(
          grid_size,
          block_size,
          (
              cov_result,
              gram_matrix,
              mean_x,
              mean_x,
              gram_matrix.shape[0],
          ),
      )
  
      if not return_gram and not return_mean:
          return cov_result
      elif return_gram and not return_mean:
          return cov_result, gram_matrix
      elif not return_gram and return_mean:
          return cov_result, mean_x, mean_x
      elif return_gram and return_mean:
          return cov_result, gram_matrix, mean_x, mean_x
  
file_path: cuml/python/cuml/prims/stats/covariance.py
imports: from cuml.common.kernel_utils import cuda_kernel_factory
  import cuml.internals
  import math
  from cuml.internals.safe_imports import gpu_only_import
label_desc: Use image node_id 6 for calling a global function with example usage: _cov_sparse(x, return_gram, return_mean) and returns: cov_result, cov_result,  gram_matrix, cov_result,  mean_x,  mean_x, cov_result,  gram_matrix,  mean_x,  mean_x