Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b8ca61a6
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看板
提交
b8ca61a6
编写于
9月 27, 2020
作者:
D
danleifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix is_empty api and code example; test=develop
上级
60d5f09c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
20 deletion
+20
-20
python/paddle/fluid/tests/unittests/test_is_empty_op.py
python/paddle/fluid/tests/unittests/test_is_empty_op.py
+20
-20
未找到文件。
python/paddle/fluid/tests/unittests/test_is_empty_op.py
浏览文件 @
b8ca61a6
...
@@ -17,7 +17,7 @@ from __future__ import print_function
...
@@ -17,7 +17,7 @@ from __future__ import print_function
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
op_test
import
OpTest
from
op_test
import
OpTest
import
paddle
.fluid
as
fluid
import
paddle
class
TestEmpty
(
OpTest
):
class
TestEmpty
(
OpTest
):
...
@@ -39,39 +39,39 @@ class TestNotEmpty(TestEmpty):
...
@@ -39,39 +39,39 @@ class TestNotEmpty(TestEmpty):
class
TestIsEmptyOpError
(
unittest
.
TestCase
):
class
TestIsEmptyOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
def
test_errors
(
self
):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
(),
paddle
.
static
.
Program
()):
input_data
=
np
.
random
.
random
((
3
,
2
)).
astype
(
"float64"
)
input_data
=
np
.
random
.
random
((
3
,
2
)).
astype
(
"float64"
)
def
test_Variable
():
def
test_Variable
():
# the input type must be Variable
# the input type must be Variable
fluid
.
layers
.
is_empty
(
x
=
input_data
)
paddle
.
is_empty
(
x
=
input_data
)
self
.
assertRaises
(
TypeError
,
test_Variable
)
self
.
assertRaises
(
TypeError
,
test_Variable
)
def
test_cond_Variable
():
# cond type must be Variable or None
x2
=
fluid
.
layers
.
data
(
name
=
"x2"
,
shape
=
[
3
,
2
],
dtype
=
"float32"
)
cond_data
=
np
.
random
.
random
((
3
,
2
)).
astype
(
"float32"
)
fluid
.
layers
.
is_empty
(
x
=
x2
,
cond
=
cond_data
)
self
.
assertRaises
(
TypeError
,
test_cond_Variable
)
def
test_type
():
def
test_type
():
# dtype must be float32, float64, int32, int64
# dtype must be float32, float64, int32, int64
x3
=
fluid
.
layers
.
data
(
x3
=
paddle
.
static
.
data
(
name
=
"x3"
,
shape
=
[
4
,
32
,
32
],
dtype
=
"bool"
)
name
=
"x3"
,
shape
=
[
4
,
32
,
32
],
dtype
=
"bool"
)
res
=
fluid
.
layers
.
is_empty
(
x
=
x3
)
res
=
paddle
.
is_empty
(
x
=
x3
)
self
.
assertRaises
(
TypeError
,
test_type
)
self
.
assertRaises
(
TypeError
,
test_type
)
def
test_cond_type
():
def
test_name_type
():
# cond dtype must be bool.
# name type must be string.
x4
=
fluid
.
layers
.
data
(
name
=
"x4"
,
shape
=
[
3
,
2
],
dtype
=
"float32"
)
x4
=
paddle
.
static
.
data
(
cond
=
fluid
.
layers
.
data
(
name
=
"x4"
,
shape
=
[
3
,
2
],
dtype
=
"float32"
)
name
=
"cond"
,
shape
=
[
1
],
dtype
=
"float32"
)
res
=
paddle
.
is_empty
(
x
=
x4
,
name
=
1
)
fluid
.
layers
.
is_empty
(
x
=
x4
,
cond
=
cond
)
self
.
assertRaises
(
TypeError
,
test_name_type
)
self
.
assertRaises
(
TypeError
,
test_cond_type
)
class
TestIsEmptyOpDygraph
(
unittest
.
TestCase
):
def
test_dygraph
(
self
):
paddle
.
disable_static
()
input
=
paddle
.
rand
(
shape
=
[
4
,
32
,
32
],
dtype
=
'float32'
)
res
=
paddle
.
is_empty
(
x
=
input
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录