未验证 提交 3eb12bd1 编写于 作者: W wangchaochaohu 提交者: GitHub

refine the usage of paddle.full test=develop (#23484)

上级 eb035f24
...@@ -21,7 +21,7 @@ from op_test import OpTest ...@@ -21,7 +21,7 @@ from op_test import OpTest
import paddle.fluid.core as core import paddle.fluid.core as core
from paddle.fluid.op import Operator from paddle.fluid.op import Operator
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.tensor as tensor import paddle
from paddle.fluid import compiler, Program, program_guard from paddle.fluid import compiler, Program, program_guard
...@@ -37,35 +37,35 @@ class TestFullAPI(unittest.TestCase): ...@@ -37,35 +37,35 @@ class TestFullAPI(unittest.TestCase):
shape_tensor_int64 = fluid.data( shape_tensor_int64 = fluid.data(
name="shape_tensor_int64", shape=[2], dtype="int64") name="shape_tensor_int64", shape=[2], dtype="int64")
out_1 = tensor.full( out_1 = paddle.full(
shape=[1, 2], dtype="float32", fill_value=1.1, device='gpu') shape=[1, 2], dtype="float32", fill_value=1.1, device='gpu')
out_2 = tensor.full( out_2 = paddle.full(
shape=[1, positive_2_int32], shape=[1, positive_2_int32],
dtype="float32", dtype="float32",
fill_value=1.1, fill_value=1.1,
device='cpu') device='cpu')
out_3 = tensor.full( out_3 = paddle.full(
shape=[1, positive_2_int64], shape=[1, positive_2_int64],
dtype="float32", dtype="float32",
fill_value=1.1, fill_value=1.1,
device='gpu') device='gpu')
out_4 = tensor.full( out_4 = paddle.full(
shape=shape_tensor_int32, shape=shape_tensor_int32,
dtype="float32", dtype="float32",
fill_value=1.2, fill_value=1.2,
out=out_3) out=out_3)
out_5 = tensor.full( out_5 = paddle.full(
shape=shape_tensor_int64, shape=shape_tensor_int64,
dtype="float32", dtype="float32",
fill_value=1.1, fill_value=1.1,
device='gpu', device='gpu',
stop_gradient=False) stop_gradient=False)
out_6 = tensor.full( out_6 = paddle.full(
shape=shape_tensor_int64, dtype=np.float32, fill_value=1.1) shape=shape_tensor_int64, dtype=np.float32, fill_value=1.1)
exe = fluid.Executor(place=fluid.CPUPlace()) exe = fluid.Executor(place=fluid.CPUPlace())
...@@ -91,10 +91,10 @@ class TestFullOpError(unittest.TestCase): ...@@ -91,10 +91,10 @@ class TestFullOpError(unittest.TestCase):
#for ci coverage #for ci coverage
x1 = fluid.layers.data(name='x1', shape=[1], dtype="int16") x1 = fluid.layers.data(name='x1', shape=[1], dtype="int16")
self.assertRaises( self.assertRaises(
ValueError, tensor.full, shape=[1], fill_value=5, dtype='uint4') ValueError, paddle.full, shape=[1], fill_value=5, dtype='uint4')
self.assertRaises( self.assertRaises(
TypeError, TypeError,
tensor.full, paddle.full,
shape=[1], shape=[1],
fill_value=5, fill_value=5,
dtype='int16', dtype='int16',
...@@ -105,17 +105,17 @@ class TestFullOpError(unittest.TestCase): ...@@ -105,17 +105,17 @@ class TestFullOpError(unittest.TestCase):
x2 = fluid.layers.data(name='x2', shape=[1], dtype="int32") x2 = fluid.layers.data(name='x2', shape=[1], dtype="int32")
self.assertRaises( self.assertRaises(
TypeError, tensor.full, shape=[1], fill_value=5, dtype='uint8') TypeError, paddle.full, shape=[1], fill_value=5, dtype='uint8')
# The argument shape's type of full_op must be list, tuple or Variable. # The argument shape's type of full_op must be list, tuple or Variable.
def test_shape_type(): def test_shape_type():
tensor.full(shape=1, dtype="float32", fill_value=1) paddle.full(shape=1, dtype="float32", fill_value=1)
self.assertRaises(TypeError, test_shape_type) self.assertRaises(TypeError, test_shape_type)
# The argument shape's size of full_op must not be 0. # The argument shape's size of full_op must not be 0.
def test_shape_size(): def test_shape_size():
tensor.full(shape=[], dtype="float32", fill_value=1) paddle.full(shape=[], dtype="float32", fill_value=1)
self.assertRaises(AssertionError, test_shape_size) self.assertRaises(AssertionError, test_shape_size)
...@@ -123,14 +123,14 @@ class TestFullOpError(unittest.TestCase): ...@@ -123,14 +123,14 @@ class TestFullOpError(unittest.TestCase):
def test_shape_tensor_dtype(): def test_shape_tensor_dtype():
shape = fluid.data( shape = fluid.data(
name="shape_tensor", shape=[2], dtype="float32") name="shape_tensor", shape=[2], dtype="float32")
tensor.full(shape=shape, dtype="float32", fill_value=1) paddle.full(shape=shape, dtype="float32", fill_value=1)
self.assertRaises(TypeError, test_shape_tensor_dtype) self.assertRaises(TypeError, test_shape_tensor_dtype)
def test_shape_tensor_list_dtype(): def test_shape_tensor_list_dtype():
shape = fluid.data( shape = fluid.data(
name="shape_tensor_list", shape=[1], dtype="bool") name="shape_tensor_list", shape=[1], dtype="bool")
tensor.full(shape=[shape, 2], dtype="float32", fill_value=1) paddle.full(shape=[shape, 2], dtype="float32", fill_value=1)
self.assertRaises(TypeError, test_shape_tensor_list_dtype) self.assertRaises(TypeError, test_shape_tensor_list_dtype)
......
...@@ -370,19 +370,19 @@ def full(shape, ...@@ -370,19 +370,19 @@ def full(shape,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.tensor as tensor import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
data1 = tensor.full(shape=[2,1], full_value=0, dtype='int64') # data1=[[0],[0]] data1 = paddle.full(shape=[2,1], full_value=0, dtype='int64') # data1=[[0],[0]]
data2 = tensor.full(shape=[2,1], full_value=5, dtype='int64', device='gpu') # data2=[[5],[5]] data2 = paddle.full(shape=[2,1], full_value=5, dtype='int64', device='gpu') # data2=[[5],[5]]
# attr shape is a list which contains Variable Tensor. # attr shape is a list which contains Variable Tensor.
positive_2 = fluid.layers.fill_constant([1], "int32", 2) positive_2 = fluid.layers.fill_constant([1], "int32", 2)
data3 = tensor.full(shape=[1, positive_2], dtype='float32', full_value=1.5) # data3=[1.5, 1.5] data3 = paddle.full(shape=[1, positive_2], dtype='float32', full_value=1.5) # data3=[1.5, 1.5]
# attr shape is an Variable Tensor. # attr shape is an Variable Tensor.
shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2] shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2]
data4 = tensor.full(shape=shape, dtype='bool', full_value=True) # data4=[[True,True],[True,True]] data4 = paddle.full(shape=shape, dtype='bool', full_value=True) # data4=[[True,True],[True,True]]
""" """
helper = LayerHelper("full", **locals()) helper = LayerHelper("full", **locals())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册