未验证 提交 505f4100 编写于 作者: 2 201716010711 提交者: GitHub

delete size api (#48397)

上级 af3fabf9
......@@ -116,7 +116,6 @@ __all__ = [
'sum',
'slice',
'shape',
'size',
'clip',
'clip_by_norm',
'mean',
......@@ -6912,53 +6911,6 @@ def shape(input):
return out
@deprecated(since="2.0.0", update_to="paddle.numel")
def size(input):
"""
**Size Layer**
Returns the number of elements for a tensor, which is a int64 Tensor with shape [1].
Args:
input (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, int32, int64.
Returns:
Tensor: The number of elements for the input Tensor.
Raises:
TypeError: ``input`` must be a Tensor and the data type of ``input`` must be one of bool, float16, float32, float64, int32, int64.
Examples:
.. code-block:: python
import paddle
import paddle.fluid.layers as layers
paddle.enable_static()
input = layers.data(
name="input", shape=[3, 100], dtype="float32", append_batch_size=False)
rank = layers.size(input) # 300
"""
if in_dygraph_mode():
return _C_ops.numel(input)
if _in_legacy_dygraph():
return _legacy_C_ops.size(input)
check_variable_and_dtype(
input,
'input',
['bool', 'float16', 'float32', 'float64', 'int32', 'int64'],
"size",
)
helper = LayerHelper('size', **locals())
out = helper.create_variable_for_type_inference(dtype='int64')
helper.append_op(type='size', inputs={'Input': input}, outputs={'Out': out})
return out
def _elementwise_op(helper):
op_type = helper.layer_type
x = helper.kwargs.get('x', None)
......
......@@ -71,8 +71,8 @@ class TestSizeAPI(unittest.TestCase):
x_2 = paddle.fluid.data(shape=shape2, dtype='int32', name='x_2')
input_1 = np.random.random(shape1).astype("int32")
input_2 = np.random.random(shape2).astype("int32")
out_1 = paddle.fluid.layers.size(x_1)
out_2 = paddle.fluid.layers.size(x_2)
out_1 = paddle.numel(x_1)
out_2 = paddle.numel(x_2)
exe = paddle.static.Executor(place=paddle.MLUPlace(0))
res_1, res_2 = exe.run(
feed={
......@@ -94,8 +94,8 @@ class TestSizeAPI(unittest.TestCase):
input_2 = np.random.random([1, 4, 5]).astype("int32")
x_1 = paddle.to_tensor(input_1)
x_2 = paddle.to_tensor(input_2)
out_1 = paddle.fluid.layers.size(x_1)
out_2 = paddle.fluid.layers.size(x_2)
out_1 = paddle.numel(x_1)
out_2 = paddle.numel(x_2)
assert np.array_equal(out_1.numpy().item(0), np.size(input_1))
assert np.array_equal(out_2.numpy().item(0), np.size(input_2))
paddle.enable_static()
......@@ -108,7 +108,7 @@ class TestSizeAPI(unittest.TestCase):
def test_x_type():
shape = [1, 4, 5]
input_1 = np.random.random(shape).astype("int32")
out_1 = paddle.fluid.layers.size(input_1)
out_1 = paddle.numel(input_1)
self.assertRaises(TypeError, test_x_type)
......
......@@ -100,8 +100,8 @@ class TestSizeAPI(unittest.TestCase):
x_2 = paddle.fluid.data(shape=shape2, dtype='int32', name='x_2')
input_1 = np.random.random(shape1).astype("int32")
input_2 = np.random.random(shape2).astype("int32")
out_1 = paddle.fluid.layers.size(x_1)
out_2 = paddle.fluid.layers.size(x_2)
out_1 = paddle.numel(x_1)
out_2 = paddle.numel(x_2)
exe = paddle.static.Executor(place=self.place)
res_1, res_2 = exe.run(
feed={
......@@ -123,8 +123,8 @@ class TestSizeAPI(unittest.TestCase):
input_2 = np.random.random([1, 4, 5]).astype("int32")
x_1 = paddle.to_tensor(input_1)
x_2 = paddle.to_tensor(input_2)
out_1 = paddle.fluid.layers.size(x_1)
out_2 = paddle.fluid.layers.size(x_2)
out_1 = paddle.numel(x_1)
out_2 = paddle.numel(x_2)
assert np.array_equal(out_1.numpy().item(0), np.size(input_1))
assert np.array_equal(out_2.numpy().item(0), np.size(input_2))
paddle.enable_static()
......@@ -137,7 +137,7 @@ class TestSizeAPI(unittest.TestCase):
def test_x_type():
shape = [1, 4, 5]
input_1 = np.random.random(shape).astype("int32")
out_1 = paddle.fluid.layers.size(input_1)
out_1 = paddle.numel(input_1)
self.assertRaises(TypeError, test_x_type)
......
......@@ -17,6 +17,7 @@ import numpy as np
import paddle
import paddle.fluid as fluid
from op_test import OpTest
import paddle
class TestSizeOp(OpTest):
......@@ -66,8 +67,8 @@ class TestSizeAPI(unittest.TestCase):
x_2 = paddle.fluid.data(shape=shape2, dtype='int32', name='x_2')
input_1 = np.random.random(shape1).astype("int32")
input_2 = np.random.random(shape2).astype("int32")
out_1 = paddle.fluid.layers.size(x_1)
out_2 = paddle.fluid.layers.size(x_2)
out_1 = paddle.numel(x_1)
out_2 = paddle.numel(x_2)
exe = paddle.static.Executor(place=paddle.CPUPlace())
res_1, res_2 = exe.run(
feed={
......@@ -90,8 +91,8 @@ class TestSizeAPI(unittest.TestCase):
input_2 = np.random.random([1, 4, 5]).astype("int32")
x_1 = paddle.to_tensor(input_1)
x_2 = paddle.to_tensor(input_2)
out_1 = paddle.fluid.layers.size(x_1)
out_2 = paddle.fluid.layers.size(x_2)
out_1 = paddle.numel(x_1)
out_2 = paddle.numel(x_2)
assert np.array_equal(out_1.numpy().item(0), np.size(input_1))
assert np.array_equal(out_2.numpy().item(0), np.size(input_2))
paddle.enable_static()
......@@ -104,7 +105,7 @@ class TestSizeAPI(unittest.TestCase):
def test_x_type():
shape = [1, 4, 5]
input_1 = np.random.random(shape).astype("int32")
out_1 = paddle.fluid.layers.size(input_1)
out_1 = paddle.numel(input_1)
self.assertRaises(TypeError, test_x_type)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册