code: def _approximate_mode(class_counts, n_draws, rng):
      """
      CuPy implementataiton based on scikit-learn approximate_mode method.
      https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/__init__.py#L984
  
      It is the mostly likely outcome of drawing n_draws many
      samples from the population given by class_counts.
  
      Parameters
      ----------
      class_counts : ndarray of int
          Population per class.
      n_draws : int
          Number of draws (samples to draw) from the overall population.
      rng : random state
          Used to break ties.
  
      Returns
      -------
      sampled_classes : cupy array of int
          Number of samples drawn from each class.
          np.sum(sampled_classes) == n_draws
      """
      # this computes a bad approximation to the mode of the
      # multivariate hypergeometric given by class_counts and n_draws
      continuous = n_draws * class_counts / class_counts.sum()
      # floored means we don't overshoot n_samples, but probably undershoot
      floored = cp.floor(continuous)
      # we add samples according to how much "left over" probability
      # they had, until we arrive at n_samples
      need_to_add = int(n_draws - floored.sum())
      if need_to_add > 0:
          remainder = continuous - floored
          values = cp.sort(cp.unique(remainder))[::-1]
          # add according to remainder, but break ties
          # randomly to avoid biases
          for value in values:
              (inds,) = cp.where(remainder == value)
              # if we need_to_add less than what's in inds
              # we draw randomly from them.
              # if we need to add more, we add them all and
              # go to the next value
              add_now = min(len(inds), need_to_add)
              inds = rng.choice(inds, size=add_now, replace=False)
              floored[inds] += 1
              need_to_add -= add_now
              if need_to_add == 0:
                  break
      return floored.astype(int)
  
file_path: cuml/python/cuml/model_selection/_split.py
imports: from typing import Optional, Union
  from cuml.common import input_to_cuml_array
  from cuml.internals.array import array_to_memory_order
  from cuml.internals.safe_imports import cpu_only_import, gpu_only_import, gpu_only_import_from
label_desc: Use image node_id 2 for calling a global function with example usage: _approximate_mode(class_counts, n_draws, rng) and returns: floored