code: def extract_pairwise_dists(pw_dists, n_neighbors):
      """
      Extract the nearest neighbors distances and indices
      from a pairwise distance matrix.
  
      Parameters
      ----------
          pw_dists: paiwise distances matrix of shape (n_samples, n_samples)
          n_neighbors: number of nearest neighbors
  
      (inspired from Scikit-Learn code)
      """
      pw_dists, _, _, _ = input_to_cupy_array(pw_dists)
  
      n_rows = pw_dists.shape[0]
      sample_range = cp.arange(n_rows)[:, None]
      knn_indices = cp.argpartition(pw_dists, n_neighbors - 1, axis=1)
      knn_indices = knn_indices[:, :n_neighbors]
      argdist = cp.argsort(pw_dists[sample_range, knn_indices])
      knn_indices = knn_indices[sample_range, argdist]
      knn_dists = pw_dists[sample_range, knn_indices]
      return knn_indices, knn_dists
  
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 9 for calling a global function with example usage: extract_pairwise_dists(pw_dists, n_neighbors) and returns: knn_indices,  knn_dists