From e112ea2b76bb007d3f3cb9355a384967b2afcf99 Mon Sep 17 00:00:00 2001 From: hong <43953930+phlrain@users.noreply.github.com> Date: Thu, 7 Nov 2019 10:45:26 +0800 Subject: [PATCH] fix uniform random (#21009) (#21057) * 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 40a60f78a37..26486ef08f7 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -17885,7 +17885,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 92ac6be3c2d..53a1e1ea167 100644 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py +++ b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py @@ -335,5 +335,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