class_docstr: Find closest anchors using :mod:`torch_sparse` on a GPU.
class_docstr_tok: ["Find","closest","anchors","using",":","mod",":","`","torch_sparse","`","on","a","GPU","."]
docstr: Select $k$ anchors from the given pools.
  
  :param pool: shape: (n, a)
      the anchor candidates for each node with distances
  :param k:
      the number of candidates to select
  
  :return: shape: (n, k)
      the selected anchors. May contain -1 if there is an insufficient number of  candidates
docstr_tok: ["Select","$","k","$","anchors","from","the","given","pools",".",":","param","pool",":","shape",":","(","n",",","a",")","the","anchor","candidates","for","each","node","with","distances",":","param","k",":","the","number","of","candidates","to","select",":","return",":","shape",":","(","n",",","k",")","the","selected","anchors",".","May","contain","-1","if","there","is","an","insufficient","number","of","candidates"]
code: def select(
      pool: torch.tensor,
      k: int,
  ) -> numpy.ndarray:
      """
      Select $k$ anchors from the given pools.
  
      :param pool: shape: (n, a)
          the anchor candidates for each node with distances
      :param k:
          the number of candidates to select
  
      :return: shape: (n, k)
          the selected anchors. May contain -1 if there is an insufficient number of  candidates
      """
      # sort the pool by nearest to farthest anchors
      values, indices = torch.sort(pool, dim=-1)
      # values with distance 255 (or max for unsigned int8 type) are padding tokens
      indices[values == torch.iinfo(values.dtype).max] = -1
      # since the output is sorted, no need for random sampling, we just take top-k nearest
      tokens = indices[:, :k].detach().cpu().numpy()
      return tokens
  
imports: import logging
  from abc import ABC, abstractmethod
  from typing import Iterable, Optional
  import numpy
  import scipy.sparse
  import torch
  from class_resolver import ClassResolver, OptionalKwargs
  from torch_ppr import page_rank
  from torch_ppr.utils import edge_index_to_sparse_matrix, prepare_page_rank_adjacency, prepare_x0
  from tqdm.auto import tqdm
  from .utils import ensure_num_entities
  from ...typing import DeviceHint
  from ...utils import ExtraReprMixin, format_relative_comparison, resolve_device
label_desc: Use image node_id 5 for calling the SparseBFSSearcher obj's underlying member method code with example usage: obj.select(pool, k) and returns: tokens