diff --git a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py index ca18a07753b473d6dd06c39615b4994c3ffae407..92ac6be3c2d2d231a970af6f9a9028bdd64f97ab 100644 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py +++ b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py @@ -243,6 +243,32 @@ class TestUniformRandomOp_attr_tensor_API(unittest.TestCase): outs = exe.run(train_program, fetch_list=[ret]) +class TestUniformRandomOp_API_seed(unittest.TestCase): + def test_attr_tensor_API(self): + startup_program = fluid.Program() + train_program = fluid.Program() + with fluid.program_guard(train_program, startup_program): + _min = 5 + _max = 10 + _seed = 10 + ret = fluid.layers.nn.uniform_random( + [2, 3, 2], min=_min, max=_max, seed=_seed) + ret_2 = fluid.layers.nn.uniform_random( + [2, 3, 2], min=_min, max=_max, seed=_seed) + res = fluid.layers.equal(ret, ret_2) + place = fluid.CPUPlace() + if fluid.core.is_compiled_with_cuda(): + place = fluid.CUDAPlace(0) + exe = fluid.Executor(place) + + exe.run(startup_program) + ret_value, cmp_value = exe.run(train_program, fetch_list=[ret, res]) + self.assertTrue(np.array(cmp_value).all()) + for i in ret_value.flatten(): + self.assertGreaterEqual(i, _min) + self.assertLess(i, _max) + + class TestUniformRandomOpSelectedRowsShapeTensor(unittest.TestCase): def get_places(self): places = [core.CPUPlace()]