class_docstr: Test cases for random-number generating operators.
code: def testSamplingCorrectness(self):
      np.random.seed(1618)  # Make it reproducible.
      num_samples = 40000
  
      rand_probs = np.random.dirichlet([1.0, 1.0, 2.0, 3.0])
      rand_probs2 = np.random.dirichlet(
          [1.0, 4.0, 5.0], size=3
      )  # batched
      for probs in [
          [0.5, 0.5],
          [0.85, 0.05, 0.1],
          rand_probs,
          rand_probs2,
      ]:
          probs = np.asarray(probs)
          if len(probs.shape) == 1:
              probs = probs.reshape(1, probs.size)  # singleton batch
  
          logits = np.log(probs).astype(np.float32)
          freqs = self._do_sampling(logits, num_samples)
  
          # the test here is similar to
          # python/kernel_tests/random/multinomial_op_test.py
          # Note that df >= 1 in all these cases. Choosing a cutoff of 1e-3
          # corresponds to an alpha value of 2.5% for df = 1, and smaller for larger
          # df.
          chi2 = self._chi2(probs, freqs)
          self.assertLess(chi2, 1e-3)
  
imports: import collections
  import numpy
  from tensorflow.compiler.tests import xla_test
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import random_seed
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops import stateless_random_ops
  from tensorflow.python.platform import googletest
  from tensorflow.python.platform import test
label_desc: Use image node_id 7 for calling the CategoricalTest obj's underlying member method code with example usage: obj.testSamplingCorrectness() without return types