Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
60d5f09c
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
60d5f09c
编写于
9月 27, 2020
作者:
D
danleifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix is_empty api and code example; test=develop
上级
9b124014
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
43 addition
and
18 deletion
+43
-18
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+43
-18
未找到文件。
python/paddle/fluid/layers/control_flow.py
浏览文件 @
60d5f09c
...
@@ -3788,7 +3788,7 @@ def reorder_lod_tensor_by_rank(x, rank_table):
...
@@ -3788,7 +3788,7 @@ def reorder_lod_tensor_by_rank(x, rank_table):
return
out
return
out
def
is_empty
(
x
,
cond
=
None
):
def
is_empty
(
x
,
name
=
None
):
"""
"""
:alias_main: paddle.is_empty
:alias_main: paddle.is_empty
:alias: paddle.is_empty,paddle.tensor.is_empty,paddle.tensor.logic.is_empty
:alias: paddle.is_empty,paddle.tensor.is_empty,paddle.tensor.logic.is_empty
...
@@ -3798,35 +3798,60 @@ def is_empty(x, cond=None):
...
@@ -3798,35 +3798,60 @@ def is_empty(x, cond=None):
Args:
Args:
x (Variable): The Variable to be tested.
x (Variable): The Variable to be tested.
cond (Variable, optional): Output parameter. Default: None. If this parameter is given, it
name (str, optional): The default value is ``None`` . Normally users
saves the test result of given 'x'.
don't have to set this parameter. For more information,
please refer to :ref:`api_guide_Name` .
Returns:
Returns:
Variable: A bool scalar. True if 'x' is an empty Variable.
Variable: A bool scalar. True if 'x' is an empty Variable.
Raises:
TypeError: If input cond is not a variable, or cond's dtype is
not bool.
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle.fluid as fluid
# static mode
input = fluid.layers.data(name="input", shape=[4, 32, 32], dtype="float32")
import numpy as np
res = fluid.layers.is_empty(x=input)
import paddle
# or:
# fluid.layers.is_empty(x=input, cond=res)
paddle.enable_static()
input = paddle.static.data(name="input", shape=[4, 32, 32], dtype="float32")
res = paddle.is_empty(x=input)
exe = paddle.static.Executor(paddle.CPUPlace())
data = np.ones((4, 32, 32)).astype(np.float32)
out = exe.run(feed={'input':data}, fetch_list=[res])
print("is_empty: ", out)
# ('out:', [array([False])])
.. code-block:: python
# dygraph_mode
import paddle
input = paddle.rand(shape=[4, 32, 32], dtype='float32')
res = paddle.is_empty(x=input)
print("res:", res)
# ('res:', Tensor: eager_tmp_1
# - place: CPUPlace
# - shape: [1]
# - layout: NCHW
# - dtype: bool
# - data: [0])
"""
"""
if
in_dygraph_mode
():
assert
isinstance
(
x
,
Variable
),
"The input data 'x' in is_empty must be Variable in dygraph mode"
return
core
.
ops
.
is_empty
(
x
)
check_variable_and_dtype
(
x
,
'x'
,
[
'float32'
,
'float64'
,
'int32'
,
'int64'
],
check_variable_and_dtype
(
x
,
'x'
,
[
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'is_empty'
)
'is_empty'
)
check_type
(
cond
,
'cond'
,
(
Variable
,
type
(
None
)),
'is_empty'
)
check_type
(
name
,
"name"
,
(
str
,
type
(
None
)),
"is_empty"
)
helper
=
LayerHelper
(
"is_empty"
,
**
locals
())
helper
=
LayerHelper
(
"is_empty"
,
**
locals
())
if
cond
is
None
:
cond
=
helper
.
create_variable_for_type_inference
(
dtype
=
'bool'
)
cond
=
helper
.
create_variable_for_type_inference
(
dtype
=
'bool'
)
cond
.
stop_gradient
=
True
cond
.
stop_gradient
=
True
else
:
check_dtype
(
cond
.
dtype
,
'cond'
,
[
'bool'
],
'is_empty'
)
helper
.
append_op
(
helper
.
append_op
(
type
=
'is_empty'
,
inputs
=
{
'X'
:
[
x
]},
outputs
=
{
'Out'
:
[
cond
]})
type
=
'is_empty'
,
inputs
=
{
'X'
:
[
x
]},
outputs
=
{
'Out'
:
[
cond
]})
return
cond
return
cond
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录