code: def test_permutation_helper(self):
      # Test that raw_random.permutation_helper generates the same
      # results as numpy,
      # and that the 'ndim_added' keyword behaves correctly.
  
      # permutation_helper needs "ndim_added=1", because its output
      # is one dimension more than its "shape" argument (and there's
      # no way to determine that automatically).
      # Check the working case, over two calls to see if the random
      # state is correctly updated.
      rf = RandomFunction(
          permutation_helper, tensor.imatrix, 8, ndim_added=1
      )
      rng_R = random_state_type()
      post_r, out = rf(rng_R, (7,), 8)
  
      f = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=post_r,
                  mutable=True,
              )
          ],
          [out],
          accept_inplace=True,
      )
  
      numpy_rng = np.random.RandomState(utt.fetch_seed())
      val0 = f()
      val1 = f()
      # numpy_rng.permutation outputs one vector at a time,
      # so we call it iteratively to generate all the samples.
      numpy_val0 = np.asarray(
          [numpy_rng.permutation(8) for i in range(7)]
      )
      numpy_val1 = np.asarray(
          [numpy_rng.permutation(8) for i in range(7)]
      )
      self.assertTrue(np.all(val0 == numpy_val0))
      self.assertTrue(np.all(val1 == numpy_val1))
  
      # This call lacks "ndim_added=1", so ndim_added defaults to 0.
      # A ValueError should be raised.
      rf0 = RandomFunction(permutation_helper, tensor.imatrix, 8)
      post_r0, out0 = rf0(rng_R, (7,), 8)
      f0 = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=post_r0,
                  mutable=True,
              )
          ],
          [out0],
          accept_inplace=True,
      )
      self.assertRaises(ValueError, f0)
  
      # Here, ndim_added is 2 instead of 1. A ValueError should be raised.
      rf2 = RandomFunction(
          permutation_helper, tensor.imatrix, 8, ndim_added=2
      )
      post_r2, out2 = rf2(rng_R, (7,), 8)
      f2 = compile.function(
          [
              compile.In(
                  rng_R,
                  value=np.random.RandomState(utt.fetch_seed()),
                  update=post_r2,
                  mutable=True,
              )
          ],
          [out2],
          accept_inplace=True,
      )
      self.assertRaises(ValueError, f2)
  
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 15 for calling the T_random_function obj's underlying member method code with example usage: obj.test_permutation_helper() without return types