From 3251f9c1ebcc1301a3ae5a84f6149e691dd239db Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Fri, 16 Oct 2020 15:08:22 +0800 Subject: [PATCH] change paddle.fluid.layers.fill_constant to paddle.full in sample codes (#27993) (#28000) --- python/paddle/fluid/layers/control_flow.py | 22 +++++++++++----------- python/paddle/tensor/creation.py | 10 +++++----- python/paddle/tensor/math.py | 2 +- python/paddle/tensor/random.py | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/python/paddle/fluid/layers/control_flow.py b/python/paddle/fluid/layers/control_flow.py index 00e9e86d974..65ca5a211e3 100755 --- a/python/paddle/fluid/layers/control_flow.py +++ b/python/paddle/fluid/layers/control_flow.py @@ -2506,21 +2506,21 @@ def case(pred_fn_pairs, default=None, name=None): paddle.enable_static() def fn_1(): - return paddle.fluid.layers.fill_constant(shape=[1, 2], dtype='float32', value=1) + return paddle.full(shape=[1, 2], dtype='float32', fill_value=1) def fn_2(): - return paddle.fluid.layers.fill_constant(shape=[2, 2], dtype='int32', value=2) + return paddle.full(shape=[2, 2], dtype='int32', fill_value=2) def fn_3(): - return paddle.fluid.layers.fill_constant(shape=[3], dtype='int32', value=3) + return paddle.full(shape=[3], dtype='int32', fill_value=3) main_program = paddle.static.default_startup_program() startup_program = paddle.static.default_main_program() with paddle.static.program_guard(main_program, startup_program): - x = paddle.fluid.layers.fill_constant(shape=[1], dtype='float32', value=0.3) - y = paddle.fluid.layers.fill_constant(shape=[1], dtype='float32', value=0.1) - z = paddle.fluid.layers.fill_constant(shape=[1], dtype='float32', value=0.2) + x = paddle.full(shape=[1], dtype='float32', fill_value=0.3) + y = paddle.full(shape=[1], dtype='float32', fill_value=0.1) + z = paddle.full(shape=[1], dtype='float32', fill_value=0.2) pred_1 = paddle.less_than(z, x) # true: 0.2 < 0.3 pred_2 = paddle.less_than(x, y) # false: 0.3 < 0.1 @@ -3626,19 +3626,19 @@ def switch_case(branch_index, branch_fns, default=None, name=None): paddle.enable_static() def fn_1(): - return paddle.fluid.layers.fill_constant(shape=[1, 2], dtype='float32', value=1) + return paddle.full(shape=[1, 2], dtype='float32', fill_value=1) def fn_2(): - return paddle.fluid.layers.fill_constant(shape=[2, 2], dtype='int32', value=2) + return paddle.full(shape=[2, 2], dtype='int32', fill_value=2) def fn_3(): - return paddle.fluid.layers.fill_constant(shape=[3], dtype='int32', value=3) + return paddle.full(shape=[3], dtype='int32', fill_value=3) main_program = paddle.static.default_startup_program() startup_program = paddle.static.default_main_program() with paddle.static.program_guard(main_program, startup_program): - index_1 = paddle.fluid.layers.fill_constant(shape=[1], dtype='int32', value=1) - index_2 = paddle.fluid.layers.fill_constant(shape=[1], dtype='int32', value=2) + index_1 = paddle.full(shape=[1], dtype='int32', fill_value=1) + index_2 = paddle.full(shape=[1], dtype='int32', fill_value=2) out_1 = paddle.static.nn.switch_case( branch_index=index_1, diff --git a/python/paddle/tensor/creation.py b/python/paddle/tensor/creation.py index d5592c7d69e..3eddc1ee1ae 100644 --- a/python/paddle/tensor/creation.py +++ b/python/paddle/tensor/creation.py @@ -312,7 +312,7 @@ def ones(shape, dtype=None, name=None): # [1 1]] # shape is a Tensor - shape = paddle.fluid.layers.fill_constant(shape=[2], dtype='int32', value=2) + shape = paddle.full(shape=[2], dtype='int32', fill_value=2) data3 = paddle.ones(shape=shape, dtype='int32') # [[1 1] # [1 1]] @@ -393,7 +393,7 @@ def zeros(shape, dtype=None, name=None): # [0. 0.]] # shape is a Tensor - shape = paddle.fluid.layers.fill_constant(shape=[2], dtype='int32', value=2) + shape = paddle.full(shape=[2], dtype='int32', fill_value=2) data3 = paddle.zeros(shape=shape, dtype='int32') # [[0 0] # [0 0]] @@ -521,18 +521,18 @@ def full(shape, fill_value, dtype=None, name=None): # [0]] # attr shape is a list which contains Tensor. - positive_2 = paddle.fluid.layers.fill_constant([1], "int32", 2) + positive_2 = paddle.full([1], 2, "int32") data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5) # [[1.5 1.5]] # attr shape is a Tensor. - shape = paddle.fluid.layers.fill_constant([2], "int32", 2) + shape = paddle.full([2], 2, "int32") data4 = paddle.full(shape=shape, dtype='bool', fill_value=True) # [[True True] # [True True]] # attr fill_value is a Tensor. - val = paddle.fluid.layers.fill_constant([1], "float32", 2.0) + val = paddle.full([1], 2.0, "float32") data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32') # [[2.0] # [2.0]] diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index c773c1cc74c..19ba7f1b38c 100755 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -170,7 +170,7 @@ def pow(x, y, name=None): print(res.numpy()) # [1 4 9] # example 2: y is a Tensor - y = paddle.fluid.layers.fill_constant(shape=[1], value=2, dtype='float32') + y = paddle.full(shape=[1], fill_value=2, dtype='float32') res = paddle.pow(x, y) print(res.numpy()) # [1 4 9] diff --git a/python/paddle/tensor/random.py b/python/paddle/tensor/random.py index 632cbbdd0e4..de7bb6f164e 100644 --- a/python/paddle/tensor/random.py +++ b/python/paddle/tensor/random.py @@ -431,8 +431,8 @@ def uniform(shape, dtype=None, min=-1.0, max=1.0, seed=0, name=None): # example 2: # attr shape is a list which contains Tensor. - dim_1 = paddle.fluid.layers.fill_constant([1], "int64", 2) - dim_2 = paddle.fluid.layers.fill_constant([1], "int32", 3) + dim_1 = paddle.full([1], 2, "int64") + dim_2 = paddle.full([1], 3, "int32") result_2 = paddle.tensor.random.uniform(shape=[dim_1, dim_2]) # [[-0.9951253, 0.30757582, 0.9899647 ], # [ 0.5864527, 0.6607096, -0.8886161 ]] -- GitLab