code: def test_knn_graph(
      input_type,
      mode,
      output_type,
      as_instance,
      nrows,
      n_feats,
      p,
      k,
      metric,
  ):
      X, _ = make_blobs(
          n_samples=nrows, n_features=n_feats, random_state=0
      )
  
      if as_instance:
          sparse_sk = sklearn.neighbors.kneighbors_graph(
              X.get(),
              k,
              mode=mode,
              metric=metric,
              p=p,
              include_self="auto",
          )
      else:
          knn_sk = skKNN(metric=metric, p=p)
          knn_sk.fit(X.get())
          sparse_sk = knn_sk.kneighbors_graph(X.get(), k, mode=mode)
  
      if input_type == "dataframe":
          X = cudf.DataFrame(X)
  
      with cuml.using_output_type(output_type):
          if as_instance:
              sparse_cu = cuml.neighbors.kneighbors_graph(
                  X,
                  k,
                  mode=mode,
                  metric=metric,
                  p=p,
                  include_self="auto",
              )
          else:
              knn_cu = cuKNN(metric=metric, p=p)
              knn_cu.fit(X)
              sparse_cu = knn_cu.kneighbors_graph(X, k, mode=mode)
  
      assert np.array_equal(sparse_sk.data.shape, sparse_cu.data.shape)
      assert np.array_equal(
          sparse_sk.indices.shape, sparse_cu.indices.shape
      )
      assert np.array_equal(
          sparse_sk.indptr.shape, sparse_cu.indptr.shape
      )
      assert np.array_equal(
          sparse_sk.toarray().shape, sparse_cu.toarray().shape
      )
  
      if output_type == "cupy" or output_type is None:
          assert cupyx.scipy.sparse.isspmatrix_csr(sparse_cu)
      else:
          assert isspmatrix_csr(sparse_cu)
  
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 15 for calling a global function with example usage: test_knn_graph(input_type, mode, output_type, as_instance, nrows, n_feats, p, k, metric) without return types