code: def test_select_proportional_to_weight(self):
      # Tests that ChoiceFromUniform selects elements, on average,
      # proportional to the their probabilities
  
      p = tensor.fmatrix()
      u = tensor.fvector()
      n = tensor.iscalar()
      m = multinomial.ChoiceFromUniform(odtype="auto")(p, u, n)
  
      f = function([p, u, n], m, allow_input_downcast=True)
  
      n_elements = 100
      n_selected = 10
      mean_rtol = 0.0005
      np.random.seed(12345)
      pvals = np.random.randint(1, 100, (1, n_elements)).astype(
          config.floatX
      )
      pvals /= pvals.sum(1)
      avg_pvals = np.zeros((n_elements,), dtype=config.floatX)
  
      for rep in range(10000):
          uni = np.random.rand(n_selected).astype(config.floatX)
          res = f(pvals, uni, n_selected)
          res = np.squeeze(res)
          avg_pvals[res] += 1
      avg_pvals /= avg_pvals.sum()
      avg_diff = np.mean(abs(avg_pvals - pvals))
      assert avg_diff < mean_rtol, avg_diff
  
imports: from __future__ import absolute_import, print_function, division
  import os
  import numpy
  import unittest
  import theano
  from theano import config, function, tensor
  from theano.compat import PY3
  from theano.misc.pkl_utils import CompatUnpickler
  from theano.sandbox import multinomial
  from theano.sandbox.rng_mrg import MRG_RandomStreams
  import theano.tests.unittest_tools
  from .config import mode_with_gpu
  from ..multinomial import GPUAMultinomialFromUniform, GPUAChoiceFromUniform
label_desc: Use image node_id 3 for calling the test_OP_wor obj's underlying member method code with example usage: obj.test_select_proportional_to_weight() without return types