class_docstr: Implementation of Walker's alias method.
  
  This method generates a random sample from given probabilities
  :math:`p_1, \dots, p_n` in :math:`O(1)` time.
  It is more efficient than :func:`~numpy.random.choice`.
  This class works on both CPU and GPU.
  
  Args:
      probs (float list): Probabilities of entries. They are normalized with
                          `sum(probs)`.
  
  See: `Wikipedia article <https://en.wikipedia.org/wiki/Alias_method>`_
code: def sample_gpu(self, shape):
      ps = cuda.cupy.random.uniform(size=shape, dtype=numpy.float32)
      vs = cuda.elementwise(
          "T ps, raw T threshold , raw S values, int32 b",
          "int32 vs",
          """
              T pb = ps * b;
              int index = __float2int_rd(pb);
              // fill_uniform sometimes returns 1.0, so we need to check index
              if (index >= b) {
                index = 0;
              }
              int lr = threshold[index] < pb - index;
              vs = values[index * 2 + lr];
              """,
          "walker_alias_sample",
      )(ps, self.threshold, self.values, len(self.threshold))
      return vs
  
file_path: chainer/chainer/utils/walker_alias.py
imports: import numpy
  import chainer
  from chainer.backends import cuda
  from chainer import device_resident
label_desc: Use image node_id 6 for calling the WalkerAlias obj's underlying member method code with example usage: obj.sample_gpu(shape) and returns: vs