diff --git a/python/paddle/fluid/tests/unittests/test_full_op.py b/python/paddle/fluid/tests/unittests/test_full_op.py index 20ba6f5dbcc1afcad0fdbb097589e052118f54ea..9c4c2d37f5a5ffbd9007d7257ddfbe9f83a599a9 100644 --- a/python/paddle/fluid/tests/unittests/test_full_op.py +++ b/python/paddle/fluid/tests/unittests/test_full_op.py @@ -21,7 +21,7 @@ from op_test import OpTest import paddle.fluid.core as core from paddle.fluid.op import Operator import paddle.fluid as fluid -import paddle.tensor as tensor +import paddle from paddle.fluid import compiler, Program, program_guard @@ -37,35 +37,35 @@ class TestFullAPI(unittest.TestCase): shape_tensor_int64 = fluid.data( 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') - out_2 = tensor.full( + out_2 = paddle.full( shape=[1, positive_2_int32], dtype="float32", fill_value=1.1, device='cpu') - out_3 = tensor.full( + out_3 = paddle.full( shape=[1, positive_2_int64], dtype="float32", fill_value=1.1, device='gpu') - out_4 = tensor.full( + out_4 = paddle.full( shape=shape_tensor_int32, dtype="float32", fill_value=1.2, out=out_3) - out_5 = tensor.full( + out_5 = paddle.full( shape=shape_tensor_int64, dtype="float32", fill_value=1.1, device='gpu', stop_gradient=False) - out_6 = tensor.full( + out_6 = paddle.full( shape=shape_tensor_int64, dtype=np.float32, fill_value=1.1) exe = fluid.Executor(place=fluid.CPUPlace()) @@ -91,10 +91,10 @@ class TestFullOpError(unittest.TestCase): #for ci coverage x1 = fluid.layers.data(name='x1', shape=[1], dtype="int16") self.assertRaises( - ValueError, tensor.full, shape=[1], fill_value=5, dtype='uint4') + ValueError, paddle.full, shape=[1], fill_value=5, dtype='uint4') self.assertRaises( TypeError, - tensor.full, + paddle.full, shape=[1], fill_value=5, dtype='int16', @@ -105,17 +105,17 @@ class TestFullOpError(unittest.TestCase): x2 = fluid.layers.data(name='x2', shape=[1], dtype="int32") 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. 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) # The argument shape's size of full_op must not be 0. 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) @@ -123,14 +123,14 @@ class TestFullOpError(unittest.TestCase): def test_shape_tensor_dtype(): shape = fluid.data( 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) def test_shape_tensor_list_dtype(): shape = fluid.data( 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) diff --git a/python/paddle/tensor/creation.py b/python/paddle/tensor/creation.py index c97de6901f965f5434f818cb651d98b1a592b3dd..e1d00e6032609341b6674d89b5b5eb46f2ecd843 100644 --- a/python/paddle/tensor/creation.py +++ b/python/paddle/tensor/creation.py @@ -370,19 +370,19 @@ def full(shape, Examples: .. code-block:: python - import paddle.tensor as tensor + import paddle import paddle.fluid as fluid - data1 = tensor.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]] + data1 = paddle.full(shape=[2,1], full_value=0, dtype='int64') # data1=[[0],[0]] + 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. 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. 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())