def test_random_function_ndim(self):
        rng_R = random_state_type()

        # ndim is an optional argument indicating the length of the 'shape'
        # ndim not specified, OK
        post_out4, out4 = uniform(rng_R, (4,))

        # ndim specified, consistent with shape, OK
        post_out1_4, out1_4 = uniform(rng_R, (4, ), ndim=1)
        post_out2_4_4, out2_4_4 = uniform(rng_R, (4, 4), ndim=2)

        # ndim specified, but not compatible with shape
        self.assertRaises(ValueError, uniform, rng_R, (4,), ndim=2)

        f_ok = compile.function(
                [compile.In(rng_R,
                    value=numpy.random.RandomState(utt.fetch_seed()),
                    update=post_out2_4_4,
                    mutable=True)],
                [out4, out1_4, out2_4_4],
                accept_inplace=True)

        # The correct cases should execute properly
        o4, o1_4, o2_4_4 = f_ok()

        # Check the sanity of the answers
        self.assertTrue(numpy.allclose(o4, o1_4))
        self.assertTrue(numpy.allclose(o4, o2_4_4[0]))
Test that random_function helper function accepts argument ndim
dataset/ETHPy150Open rizar/attention-lvcsr/libs/Theano/theano/tensor/tests/test_raw_random.py/T_random_function.test_random_function_ndim