code: def test_permutation(self):
      # Test that raw_random.permutation generates the same results as numpy.
      rng_R = random_state_type()
      post_r, out = permutation(rng_R, size=(9,), n=6)
      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())
      # Check over two calls to see if the random state is correctly updated.
      # numpy_rng.permutation outputs one vector at a time,
      # so we call it iteratively to generate all the samples.
      val0 = f()
      val1 = f()
      numpy_val0 = np.asarray(
          [numpy_rng.permutation(6) for i in range(9)]
      )
      numpy_val1 = np.asarray(
          [numpy_rng.permutation(6) for i in range(9)]
      )
      self.assertTrue(np.all(val0 == numpy_val0))
      self.assertTrue(np.all(val1 == numpy_val1))
  
      # Test that we can generate a list: have size=None or ().
      for ndim in [1, None]:
          post_r, out = permutation(rng_R, n=10, size=None, ndim=ndim)
          inp = compile.In(
              rng_R,
              value=np.random.RandomState(utt.fetch_seed()),
              update=post_r,
              mutable=True,
          )
          f = theano.function([inp], out)
          o = f()
          assert o.shape == (10,)
          assert (np.sort(o) == np.arange(10)).all()
      # Wrong number of dimensions asked
      self.assertRaises(
          TypeError, permutation, rng_R, size=None, ndim=2
      )
  
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 18 for calling the T_random_function obj's underlying member method code with example usage: obj.test_permutation() without return types