code: def valid_metrics_sparse(algo="brute", cuml_algo=None):
      """
      The list of sparse prims in scikit-learn / scipy does not
      include sparse inputs for all of the metrics we support in cuml
      (even metrics which are implicitly sparse, such as jaccard and dice,
      which accume boolean inputs). To maintain high test coverage for all
      metrics supported by Scikit-learn, we take the union of both
      dense and sparse metrics. This way, a sparse input can just be converted
      to dense form for Scikit-learn.
      """
      cuml_algo = algo if cuml_algo is None else cuml_algo
      cuml_metrics = cuml.neighbors.VALID_METRICS_SPARSE[cuml_algo]
      sklearn_metrics = set(
          sklearn.neighbors.VALID_METRICS_SPARSE[algo]
      )
      sklearn_metrics.update(sklearn.neighbors.VALID_METRICS[algo])
      ret = [
          value for value in cuml_metrics if value in sklearn_metrics
      ]
      ret.sort()
      return ret
  
imports: import gc
  from cuml.common import has_scipy
  import cuml
  import sklearn
  from cuml.internals.safe_imports import cpu_only_import_from
  from numpy.testing import assert_array_equal, assert_allclose
  from cuml.internals.safe_imports import cpu_only_import
  import pytest
  import math
  from cuml.testing.utils import array_equal, unit_param, quality_param, stress_param
  from cuml.neighbors import NearestNeighbors
  from sklearn.neighbors import NearestNeighbors
  from cuml.datasets import make_blobs
  from sklearn.metrics import pairwise_distances
  from cuml.metrics import pairwise_distances
  from cuml.internals import logger
  from cuml.internals.safe_imports import gpu_only_import
label_desc: Use image node_id 3 for calling a global function with example usage: valid_metrics_sparse(algo, cuml_algo) and returns: ret