code: def choice_helper(random_state, a, replace, p, size):
      """
      Helper function to draw random numbers using numpy's choice function.
  
      This is a generalization of numpy.random.choice that coerces
      `replace` to a bool and replaces `p` with None when p is a vector
      of 0 elements.
  
      """
      if a.ndim > 1:
          raise ValueError("a.ndim (%i) must be 0 or 1" % a.ndim)
      if p.ndim == 1:
          if p.size == 0:
              p = None
      else:
          raise ValueError("p.ndim (%i) must be 1" % p.ndim)
      replace = bool(replace)
      return random_state.choice(a, size, replace, p)
  
imports: from __future__ import absolute_import, print_function, division
  import sys
  from copy import copy
  import numpy
  from six import string_types
  from six.moves import reduce, xrange
  import theano
  from theano import tensor
  from theano.tensor import opt
  from theano import gof
  from theano.compile import optdb
label_desc: Use image node_id 8 for calling a global function with example usage: choice_helper(random_state, a, replace, p, size) and returns: random_state