code: def test_nearest_neighbors_sparse(
      metric,
      nrows,
      ncols,
      density,
      n_neighbors,
      batch_size_index,
      batch_size_query,
  ):
      if nrows == 1 and n_neighbors > 1:
          return
  
      a = cupyx.scipy.sparse.random(
          nrows, ncols, format="csr", density=density, random_state=35
      )
      b = cupyx.scipy.sparse.random(
          nrows, ncols, format="csr", density=density, random_state=38
      )
  
      if metric == "jaccard":
          a = a.astype("bool").astype("float32")
          b = b.astype("bool").astype("float32")
  
      logger.set_level(logger.level_debug)
      nn = cuKNN(
          metric=metric,
          p=2.0,
          n_neighbors=n_neighbors,
          algorithm="brute",
          output_type="numpy",
          verbose=logger.level_debug,
          algo_params={
              "batch_size_index": batch_size_index,
              "batch_size_query": batch_size_query,
          },
      )
      nn.fit(a)
  
      cuD, cuI = nn.kneighbors(b)
  
      if metric not in sklearn.neighbors.VALID_METRICS_SPARSE["brute"]:
          a = a.todense()
          b = b.todense()
  
      sknn = skKNN(
          metric=metric,
          p=2.0,
          n_neighbors=n_neighbors,
          algorithm="brute",
          n_jobs=-1,
      )
      sk_X = a.get()
      sknn.fit(sk_X)
  
      skD, skI = sknn.kneighbors(b.get())
  
      # For some reason, this will occasionally fail w/ a single
      # mismatched element in CI. Allowing the single mismatch for now.
      cp.testing.assert_allclose(cuD, skD, atol=1e-5, rtol=1e-5)
  
      # Jaccard & Chebyshev have a high potential for mismatched indices
      # due to duplicate distances. We can ignore the indices in this case.
      if metric not in ["jaccard", "chebyshev"]:
          # The actual neighbors returned in the presence of duplicate distances
          # is non-deterministic. If we got to this point, the distances all
          # match between cuml and sklearn. We set a reasonable threshold
          # (.5% in this case) to allow differences from non-determinism.
          diffs = abs(cuI - skI)
          assert (len(diffs[diffs > 0]) / len(np.ravel(skI))) <= 0.005
  
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 17 for calling a global function with example usage: test_nearest_neighbors_sparse(metric, nrows, ncols, density, n_neighbors, batch_size_index, batch_size_query) without return types