class_docstr: Converts samples from a uniform into sample from a multinomial.
class_docstr_tok: ["Converts","samples","from","a","uniform","into","sample","from","a","multinomial","."]
code: def perform(self, node, ins, outs):
      # support old pickled graphs
      if len(ins) == 2:
          (pvals, unis) = ins
          n_samples = 1
      else:
          (pvals, unis, n_samples) = ins
      (z,) = outs
  
      if unis.shape[0] != pvals.shape[0] * n_samples:
          raise ValueError(
              "unis.shape[0] != pvals.shape[0] * n_samples",
              unis.shape[0],
              pvals.shape[0],
              n_samples,
          )
      if z[0] is None or z[0].shape != pvals.shape:
          z[0] = np.zeros(pvals.shape, dtype=node.outputs[0].dtype)
      else:
          z[0].fill(0)
  
      nb_multi = pvals.shape[0]
      # Original version that is not vectorized. I keep it here as
      # it is more readable.
      # For each multinomial, loop over each possible outcome
      # nb_outcomes = pvals.shape[1]
      # for c in range(n_samples):
      #    for n in range(nb_multi):
      #        waiting = True
      #        cummul = 0
      #        unis_n = unis[c * nb_multi + n]
      #        for m in range(nb_outcomes):
      #            cummul += pvals[n, m]
      #            if c == 0:
      #                if (waiting and (cummul > unis_n)):
      #                    z[0][n, m] = 1
      #                    waiting = False
      #                else:
      #                    # Only needed if we don't init the output to 0
      #                    z[0][n, m] = 0
      #            else:
      #                if (cummul > unis_n):
      #                    z[0][n, m] += 1
      #                    break
  
      # Vectorized version that is much faster as all the looping is
      # done in C even if this make extra work.
      for c in range(n_samples):
          for n in range(nb_multi):
              unis_n = unis[c * nb_multi + n]
              # The dtype='float64' is important. Otherwise we don't
              # have the same answer as the c code as in the c code
              # the cumul is in double precission.
              cumsum = pvals[n].cumsum(dtype="float64")
              z[0][n, np.searchsorted(cumsum, unis_n)] += 1
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import warnings
  import theano
  from theano import Op, Apply
  import theano.tensor
  from theano.scalar import as_scalar
  import copy
label_desc: Use image node_id 8 for calling the MultinomialFromUniform obj's underlying member method code with example usage: obj.perform(node, ins, outs) without return types