code: def sparsify_and_convert(
      dataset, conversion_format, sparsify_ratio=0.3
  ):
      """Randomly set values to 0 and produce a sparse array.
  
      Parameters
      ----------
      dataset : array
          Input array to convert
      conversion_format : string
          Type of sparse array :
          - scipy-csr: SciPy CSR sparse array
          - scipy-csc: SciPy CSC sparse array
          - scipy-coo: SciPy COO sparse array
          - cupy-csr: CuPy CSR sparse array
          - cupy-csc: CuPy CSC sparse array
          - cupy-coo: CuPy COO sparse array
      sparsify_ratio: float [0-1]
          Ratio of zeros in the sparse array
  
      Returns
      -------
      SciPy CSR array and converted array
      """
      random_loc = cp.random.choice(
          dataset.size,
          int(dataset.size * sparsify_ratio),
          replace=False,
      )
      dataset.ravel()[random_loc] = 0
  
      if conversion_format.startswith("scipy"):
          dataset = cp.asnumpy(dataset)
  
      if conversion_format == "scipy-csr":
          converted_dataset = cpu_csr_matrix(dataset)
      elif conversion_format == "scipy-csc":
          converted_dataset = cpu_csc_matrix(dataset)
      elif conversion_format == "scipy-coo":
          converted_dataset = cpu_coo_matrix(dataset)
      elif conversion_format == "cupy-csr":
          converted_dataset = gpu_csr_matrix(dataset)
      elif conversion_format == "cupy-csc":
          converted_dataset = gpu_csc_matrix(dataset)
      elif conversion_format == "cupy-coo":
          np_array = cp.asnumpy(dataset)
          np_coo_array = cpu_coo_matrix(np_array)
          converted_dataset = gpu_coo_matrix(np_coo_array)
  
      if conversion_format.startswith("cupy"):
          dataset = cp.asnumpy(dataset)
  
      return cpu_csr_matrix(dataset), converted_dataset
  
imports: from cuml.common import input_to_cuml_array
  from scipy.sparse import coo_matrix
  from scipy.sparse import csc_matrix
  from cupyx.scipy.sparse import coo_matrix
  from cuml.internals.safe_imports import gpu_only_import_from
  from cuml.internals.safe_imports import gpu_only_import
  from cuml.internals.safe_imports import cpu_only_import
  import pytest
  from cuml.datasets import make_classification, make_blobs
  from cuml.internals.safe_imports import cpu_only_import_from
label_desc: Use image node_id 7 for calling a global function with example usage: sparsify_and_convert(dataset, conversion_format, sparsify_ratio) and returns: cpu_csr_matrix,  converted_dataset