docstr: Reduce a chunk of distances to topk
  
  Parameters
  ----------
  dist : array of shape (n_samples_chunk, n_samples)
  start : int
      The index in X which the first row of dist corresponds to.
  topk : int
  
  Returns
  -------
  dist : array of shape (n_samples_chunk, n_neighbors)
  neigh : array of shape (n_samples_chunk, n_neighbors)
docstr_tok: ["Reduce","a","chunk","of","distances","to","topk","Parameters","--","--","--","--","--","dist",":","array","of","shape","(","n_samples_chunk",",","n_samples",")","start",":","int","The","index","in","X","which","the","first","row","of","dist","corresponds","to",".","topk",":","int","Returns","--","--","--","-","dist",":","array","of","shape","(","n_samples_chunk",",","n_neighbors",")","neigh",":","array","of","shape","(","n_samples_chunk",",","n_neighbors",")"]
code: def _topk_reduce_func(cls, dist, start, topk, xp, metric):
      """Reduce a chunk of distances to topk
  
      Parameters
      ----------
      dist : array of shape (n_samples_chunk, n_samples)
      start : int
          The index in X which the first row of dist corresponds to.
      topk : int
  
      Returns
      -------
      dist : array of shape (n_samples_chunk, n_neighbors)
      neigh : array of shape (n_samples_chunk, n_neighbors)
      """
      sample_range = xp.arange(dist.shape[0])[:, None]
      if topk - 1 >= dist.shape[1]:
          neigh_ind = xp.repeat(
              xp.arange(dist.shape[1]).reshape(1, -1),
              dist.shape[0],
              axis=0,
          )
      else:
          neigh_ind = xp.argpartition(dist, topk - 1, axis=1)
          neigh_ind = neigh_ind[:, :topk]
      # argpartition doesn't guarantee sorted order, so we sort again
      neigh_ind = neigh_ind[
          sample_range, xp.argsort(dist[sample_range, neigh_ind])
      ]
      return dist[sample_range, neigh_ind], neigh_ind
  
imports: from functools import partial
  import numpy
  from ....None import opcodes
  from ....None import options
  from ....core import recursive_tile
  from ....core.operand import OperandStage
  from ....serialization.serializables import KeyField, BoolField, DictField, Int64Field, AnyField
  from ....tensor.core import TensorOrder
  from ....tensor.merge import TensorConcatenate
  from ....tensor.array_utils import as_same_device, device, get_array_module
  from ....utils import has_unknown_shape, ensure_own_data
  from ...utils import gen_batches, get_chunk_n_rows
  from ...utils.validation import _num_samples
  from .core import PairwiseDistances
label_desc: Use image node_id 15 for calling the PairwiseDistancesTopk obj's underlying member method code with example usage: obj._topk_reduce_func(cls, dist, start, topk, xp, metric) and returns: dist,  neigh_ind