code: def extract_knn_graph(knn_graph):
      """
      Converts KNN graph from CSR, COO and CSC formats into separate
      distance and indice arrays. Input can be a cupy sparse graph (device)
      or a numpy sparse graph (host).
      """
      if isinstance(knn_graph, (csc_matrix, cp_csc_matrix)):
          knn_graph = cupyx.scipy.sparse.csr_matrix(knn_graph)
          n_samples = knn_graph.shape[0]
          reordering = knn_graph.data.reshape((n_samples, -1))
          reordering = reordering.argsort()
          n_neighbors = reordering.shape[1]
          reordering += (cp.arange(n_samples) * n_neighbors)[
              :, np.newaxis
          ]
          reordering = reordering.flatten()
          knn_graph.indices = knn_graph.indices[reordering]
          knn_graph.data = knn_graph.data[reordering]
  
      knn_indices = None
      if isinstance(knn_graph, (csr_matrix, cp_csr_matrix)):
          knn_indices = knn_graph.indices
      elif isinstance(knn_graph, (coo_matrix, cp_coo_matrix)):
          knn_indices = knn_graph.col
  
      if knn_indices is not None:
          knn_dists = knn_graph.data
          return knn_indices, knn_dists
      else:
          return None
  
file_path: cuml/python/cuml/common/sparsefuncs.py
imports: import math
  import cuml
  from cuml.internals.input_utils import input_to_cuml_array, input_to_cupy_array
  from cuml.internals.memory_utils import with_cupy_rmm
  from cuml.internals.import_utils import has_scipy
  from cuml.common.kernel_utils import cuda_kernel_factory
  from cuml.internals.safe_imports import cpu_only_import
  from cuml.internals.safe_imports import gpu_only_import
  from cuml.internals.safe_imports import gpu_only_import_from
label_desc: Use image node_id 8 for calling a global function with example usage: extract_knn_graph(knn_graph) and returns: knn_indices,  knn_dists, None