From 72e0969b2719efc84199138a54d509673457132c Mon Sep 17 00:00:00 2001 From: hong <43953930+phlrain@users.noreply.github.com> Date: Wed, 6 Nov 2019 19:36:09 +0800 Subject: [PATCH] fix uniform random (#21009) * fix uniform random; test=develop * add uniform random test; test=develop --- python/paddle/fluid/layers/nn.py | 2 +- .../fluid/tests/unittests/test_uniform_random_op.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 0bf24f2e13d..df65e057471 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -17854,7 +17854,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): inputs = dict() attrs = {'seed': seed, 'min': min, 'max': max} if in_dygraph_mode(): - attrs = {'shape': shape} + attrs['shape'] = shape else: if isinstance(shape, Variable): shape.stop_gradient = True 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 65d534b79b0..1d388816608 100644 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py +++ b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py @@ -416,5 +416,15 @@ class TestUniformRandomOpSelectedRowsShapeTensorList(unittest.TestCase): hist, prob, rtol=0, atol=0.01), "hist: " + str(hist)) +class TestUniformRandomDygraphMode(unittest.TestCase): + def test_check_output(self): + with fluid.dygraph.guard(): + x = fluid.layers.uniform_random( + [10], dtype="float32", min=0.0, max=1.0) + x_np = x.numpy() + for i in range(10): + self.assertTrue((x_np[i] > 0 and x_np[i] < 1.0)) + + if __name__ == "__main__": unittest.main() -- GitLab