Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
505f4100
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
505f4100
编写于
11月 29, 2022
作者:
2
201716010711
提交者:
GitHub
11月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete size api (#48397)
上级
af3fabf9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
16 addition
and
63 deletion
+16
-63
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-48
python/paddle/fluid/tests/unittests/mlu/test_size_op_mlu.py
python/paddle/fluid/tests/unittests/mlu/test_size_op_mlu.py
+5
-5
python/paddle/fluid/tests/unittests/npu/test_size_op_npu.py
python/paddle/fluid/tests/unittests/npu/test_size_op_npu.py
+5
-5
python/paddle/fluid/tests/unittests/test_size_op.py
python/paddle/fluid/tests/unittests/test_size_op.py
+6
-5
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
505f4100
...
...
@@ -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
)
...
...
python/paddle/fluid/tests/unittests/mlu/test_size_op_mlu.py
浏览文件 @
505f4100
...
...
@@ -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
)
...
...
python/paddle/fluid/tests/unittests/npu/test_size_op_npu.py
浏览文件 @
505f4100
...
...
@@ -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
)
...
...
python/paddle/fluid/tests/unittests/test_size_op.py
浏览文件 @
505f4100
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录