code: def test_random_function_ndim_added(self):
      # Test that random_function helper function accepts ndim_added as
      # keyword argument
      # If using numpy's uniform distribution, ndim_added should be 0,
      # because the shape provided as argument is the output shape.
      # Specifying a different ndim_added will change the Op's output ndim,
      # so np.uniform will produce a result of incorrect shape,
      # and a ValueError should be raised.
      def ndim_added_deco(ndim_added):
          def randomfunction(
              random_state, size=(), low=0.0, high=0.0, ndim=None
          ):
              ndim, size, bcast = raw_random._infer_ndim_bcast(
                  ndim, size
              )
              if ndim_added < 0:
                  bcast = bcast[:ndim_added]
              else:
                  bcast = bcast + ((False,) * ndim_added)
              assert len(bcast) == ndim + ndim_added
              op = RandomFunction(
                  "uniform",
                  tensor.TensorType(
                      dtype="float64", broadcastable=bcast
                  ),
                  ndim_added=ndim_added,
              )
              return op(random_state, size, low, high)
  
          return randomfunction
  
      uni_1 = ndim_added_deco(1)
      uni_0 = ndim_added_deco(0)
      uni_m1 = ndim_added_deco(-1)
  
      rng_R = random_state_type()
  
      p_uni11, uni11 = uni_1(rng_R, size=(4,))
      p_uni12, uni12 = uni_1(rng_R, size=(3, 4))
      p_uni01, uni01 = uni_0(rng_R, size=(4,))
      p_uni02, uni02 = uni_0(rng_R, size=(3, 4))
      p_unim11, unim11 = uni_m1(rng_R, size=(4,))
      p_unim12, unim12 = uni_m1(rng_R, size=(3, 4))
  
      self.assertEqual(uni11.ndim, 2)
      self.assertEqual(uni12.ndim, 3)
      self.assertEqual(uni01.ndim, 1)
      self.assertEqual(uni02.ndim, 2)
      self.assertEqual(unim11.ndim, 0)
      self.assertEqual(unim12.ndim, 1)
  
      f11 = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=p_uni11,
                  mutable=True,
              )
          ],
          [uni11],
          accept_inplace=True,
      )
      f12 = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=p_uni12,
                  mutable=True,
              )
          ],
          [uni12],
          accept_inplace=True,
      )
      fm11 = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=p_unim11,
                  mutable=True,
              )
          ],
          [unim11],
          accept_inplace=True,
      )
      fm12 = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=p_unim12,
                  mutable=True,
              )
          ],
          [unim12],
          accept_inplace=True,
      )
      f0 = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=p_uni02,
                  mutable=True,
              )
          ],
          [uni01, uni02],
          accept_inplace=True,
      )
      self.assertRaises(ValueError, f11)
      self.assertRaises(ValueError, f12)
      self.assertRaises(ValueError, fm11)
      self.assertRaises(ValueError, fm12)
      u01, u02 = f0()
      self.assertTrue(np.allclose(u01, u02[0]))
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import pickle
  from theano.tests import unittest_tools
  from theano.tensor.raw_random import *
  from theano.tensor import raw_random, ivector, dvector, iscalar, dcol, dtensor3
  from theano import tensor
  from theano import compile, config, gof
label_desc: Use image node_id 10 for calling the T_random_function obj's underlying member method code with example usage: obj.test_random_function_ndim_added() and returns: randomfunction, op