未验证 提交 3251f9c1 编写于 作者: C chentianyu03 提交者: GitHub

change paddle.fluid.layers.fill_constant to paddle.full in sample codes (#27993) (#28000)

上级 164b9aab
......@@ -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,
......
......@@ -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]]
......
......@@ -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]
......
......@@ -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 ]]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册