class_docstr: Random sampler.
  
  Args:
      num (int): Number of samples
      pos_fraction (float): Fraction of positive samples
      neg_pos_up (int, optional): Upper bound number of negative and
          positive samples. Defaults to -1.
      add_gt_as_proposals (bool, optional): Whether to add ground truth
          boxes as proposals. Defaults to True.
docstr: Random select some elements from the gallery.
  
  If `gallery` is a Tensor, the returned indices will be a Tensor;
  If `gallery` is a ndarray or list, the returned indices will be a
  ndarray.
  
  Args:
      gallery (Tensor | ndarray | list): indices pool.
      num (int): expected sample num.
  
  Returns:
      Tensor or ndarray: sampled indices.
docstr_tok: ["Random","select","some","elements","from","the","gallery",".","If","`","gallery","`","is","a","Tensor",",","the","returned","indices","will","be","a","Tensor",";","If","`","gallery","`","is","a","ndarray","or","list",",","the","returned","indices","will","be","a","ndarray",".","Args",":","gallery","(","Tensor","|","ndarray","|","list",")",":","indices","pool",".","num","(","int",")",":","expected","sample","num",".","Returns",":","Tensor","or","ndarray",":","sampled","indices","."]
code: def random_choice(self, gallery, num):
      """Random select some elements from the gallery.
  
      If `gallery` is a Tensor, the returned indices will be a Tensor;
      If `gallery` is a ndarray or list, the returned indices will be a
      ndarray.
  
      Args:
          gallery (Tensor | ndarray | list): indices pool.
          num (int): expected sample num.
  
      Returns:
          Tensor or ndarray: sampled indices.
      """
      assert len(gallery) >= num
  
      is_tensor = isinstance(gallery, torch.Tensor)
      if not is_tensor:
          if torch.cuda.is_available():
              device = torch.cuda.current_device()
          else:
              device = "cpu"
          gallery = torch.tensor(
              gallery, dtype=torch.long, device=device
          )
      perm = torch.randperm(gallery.numel(), device=gallery.device)[
          :num
      ]
      rand_inds = gallery[perm]
      if not is_tensor:
          rand_inds = rand_inds.cpu().numpy()
      return rand_inds
  
file_path: insightface/detection/scrfd/mmdet/core/bbox/samplers/random_sampler.py
imports: import torch
  from ..builder import BBOX_SAMPLERS
  from .base_sampler import BaseSampler
label_desc: Use image node_id 2 for calling the RandomSampler obj's underlying member method code with example usage: obj.random_choice(gallery, num) and returns: rand_inds