class_docstr: Test cases for random-number generating operators.
docstr: Categorical samples from given input.
  
  Args:
    logits: Numpy ndarray of shape [batch_size, num_classes].
    num_samples: Int; number of samples to draw.
  
  Returns:
    Frequencies from sampled classes; shape [batch_size, num_classes].
docstr_tok: ["Categorical","samples","from","given","input",".","Args",":","logits",":","Numpy","ndarray","of","shape","[","batch_size",",","num_classes","]",".","num_samples",":","Int",";","number","of","samples","to","draw",".","Returns",":","Frequencies","from","sampled","classes",";","shape","[","batch_size",",","num_classes","]","."]
code: def _do_sampling(self, logits, num_samples):
      """Categorical samples from given input.
  
      Args:
        logits: Numpy ndarray of shape [batch_size, num_classes].
        num_samples: Int; number of samples to draw.
  
      Returns:
        Frequencies from sampled classes; shape [batch_size, num_classes].
      """
      with self.session(), self.test_scope():
          random_seed.set_random_seed(1618)
          op = random_ops.multinomial(
              logits, num_samples, output_dtype=dtypes.int32
          )
          d = self.evaluate(op)
  
      batch_size, num_classes = logits.shape
      freqs_mat = []
      for i in range(batch_size):
          cnts = dict(collections.Counter(d[i, :]))
  
          # Requires drawn class labels be in range.
          self.assertLess(max(cnts.keys()), num_classes)
          self.assertGreaterEqual(min(cnts.keys()), 0)
  
          freqs = [
              (cnts[k] * 1.0 / num_samples if k in cnts else 0)
              for k in range(num_classes)
          ]
          freqs_mat.append(freqs)
  
      return freqs_mat
  
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 3 for calling the CategoricalTest obj's underlying member method code with example usage: obj._do_sampling(logits, num_samples) and returns: freqs_mat