code: def test_undefined_grad_opt():
      # Make sure that undefined grad get removed in optimized graph.
      random = RandomStreams(np.random.randint(1, 2147462579))
      pvals = theano.shared(
          np.random.rand(10, 20).astype(theano.config.floatX)
      )
      pvals = pvals / pvals.sum(axis=1)
      pvals = gradient.zero_grad(pvals)
      samples = random.multinomial(pvals=pvals, n=1)
      samples = theano.tensor.cast(samples, pvals.dtype)
      samples = gradient.zero_grad(samples)
      cost = theano.tensor.sum(samples + pvals)
      grad = theano.tensor.grad(cost, samples)
      f = theano.function([], grad)
      theano.printing.debugprint(f)
      assert not any(
          [
              isinstance(node.op, gradient.UndefinedGrad)
              for node in f.maker.fgraph.apply_nodes
          ]
      )
  
imports: from __future__ import absolute_import, print_function, division
  from collections import OrderedDict
  import unittest
  import numpy
  from six.moves import xrange
  import theano
  from theano import gof, change_flags
  from theano.compat import izip
  from theano.tests import unittest_tools
  from theano import gradient
  from theano import config
  from theano.gof.null_type import NullType
  from theano.sandbox.rng_mrg import MRG_RandomStreams
label_desc: Use image node_id 10 for calling a global function with example usage: test_undefined_grad_opt() without return types