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 c_code(self, node, name, ins, outs, sub):
      # support old pickled graphs
      if len(ins) == 2:
          (pvals, unis) = ins
          n = 1
      else:
          (pvals, unis, n) = ins
      (z,) = outs
      if self.odtype == "auto":
          t = "PyArray_TYPE(%(pvals)s)" % locals()
      else:
          t = theano.scalar.Scalar(self.odtype).dtype_specs()[1]
          if t.startswith("theano_complex"):
              t = t.replace("theano_complex", "NPY_COMPLEX")
          else:
              t = t.upper()
      fail = sub["fail"]
      return (
          """
          if (PyArray_NDIM(%(pvals)s) != 2)
          {
              PyErr_Format(PyExc_TypeError, "pvals ndim should be 2");
              %(fail)s;
          }
          if (PyArray_NDIM(%(unis)s) != 1)
          {
              PyErr_Format(PyExc_TypeError, "unis ndim should be 2");
              %(fail)s;
          }
  
          if (PyArray_DIMS(%(unis)s)[0] != (PyArray_DIMS(%(pvals)s)[0] * %(n)s))
          {
              PyErr_Format(PyExc_ValueError, "unis.shape[0] != pvals.shape[0] * n");
              %(fail)s;
          }
  
          if ((NULL == %(z)s)
              || ((PyArray_DIMS(%(z)s))[0] != (PyArray_DIMS(%(pvals)s))[0])
              || ((PyArray_DIMS(%(z)s))[1] != (PyArray_DIMS(%(pvals)s))[1])
          )
          {
              Py_XDECREF(%(z)s);
              %(z)s = (PyArrayObject*) PyArray_EMPTY(2,
                  PyArray_DIMS(%(pvals)s),
                  %(t)s,
                  0);
              if (!%(z)s)
              {
                  PyErr_SetString(PyExc_MemoryError, "failed to alloc z output");
                  %(fail)s;
              }
          }
  
          { // NESTED SCOPE
  
          const int nb_multi = PyArray_DIMS(%(pvals)s)[0];
          const int nb_outcomes = PyArray_DIMS(%(pvals)s)[1];
          const int n_samples = %(n)s;
  
          //
          // For each multinomial, loop over each possible outcome
          //
          for (int c = 0; c < n_samples; ++c){
              for (int n = 0; n < nb_multi; ++n)
              {
                  int waiting = 1;
                  double cummul = 0.;
                  const dtype_%(unis)s* unis_n = (dtype_%(unis)s*)PyArray_GETPTR1(%(unis)s, c*nb_multi + n);
                  for (int m = 0; m < nb_outcomes; ++m)
                  {
                      dtype_%(z)s* z_nm = (dtype_%(z)s*)PyArray_GETPTR2(%(z)s, n,m);
                      const dtype_%(pvals)s* pvals_nm = (dtype_%(pvals)s*)PyArray_GETPTR2(%(pvals)s, n,m);
                      cummul += *pvals_nm;
                      if (c == 0)
                      {
                          if (waiting && (cummul > *unis_n))
                          {
                              *z_nm = 1.;
                              waiting = 0;
                          }
                          else
                          {
                              // if we re-used old z pointer, we have to clear it out.
                              *z_nm = 0.;
                          }
                      }
                      else {
                          if (cummul > *unis_n)
                          {
                              *z_nm = *z_nm + 1.;
                              break;
                          }
                      }
                  }
              }
          }
          } // END NESTED SCOPE
          """
          % locals()
      )
  
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 7 for calling the MultinomialFromUniform obj's underlying member method code with example usage: obj.c_code(node, name, ins, outs, sub) and returns: unknown