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>`_
docstr: Generates a random sample based on given probabilities.
  
  Args:
      shape (tuple of int): Shape of a return value.
  
  Returns:
      Returns a generated array with the given shape. If a sampler is in
      CPU mode the return value is a :class:`numpy.ndarray` object, and
      if it is in GPU mode the return value is a :class:`cupy.ndarray`
      object.
code: def sample(self, shape):
      """Generates a random sample based on given probabilities.
  
      Args:
          shape (tuple of int): Shape of a return value.
  
      Returns:
          Returns a generated array with the given shape. If a sampler is in
          CPU mode the return value is a :class:`numpy.ndarray` object, and
          if it is in GPU mode the return value is a :class:`cupy.ndarray`
          object.
      """
      device = self.device
      xp = device.xp
      with chainer.using_device(device):
          if xp is cuda.cupy:
              return self.sample_gpu(shape)
          else:
              return self.sample_xp(xp, shape)
  
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 4 for calling the WalkerAlias obj's underlying member method code with example usage: obj.sample(shape) and returns: self, self