提交 eb5c33cb 编写于 作者: S silingtong123 提交者: Tao Luo

Add uniform random unittest (#20485)

* test=develop, add unittest  of seed failed work

* test=develop, add unittest  of seed failed work
上级 d5aa2dd8
......@@ -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()]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册