Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
62e647c3
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
62e647c3
编写于
4月 21, 2020
作者:
G
GaoWei8
提交者:
GitHub
4月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish lod_append,lod_reset test (#23979)
上级
d2584a70
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
54 deletion
+45
-54
python/paddle/fluid/tests/unittests/test_lod_append_op.py
python/paddle/fluid/tests/unittests/test_lod_append_op.py
+27
-35
python/paddle/fluid/tests/unittests/test_lod_reset_op.py
python/paddle/fluid/tests/unittests/test_lod_reset_op.py
+18
-19
未找到文件。
python/paddle/fluid/tests/unittests/test_lod_append_op.py
浏览文件 @
62e647c3
...
...
@@ -29,9 +29,12 @@ class TestLoDAppendAPI(unittest.TestCase):
main_program
=
Program
()
with
fluid
.
program_guard
(
main_program
):
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
6
],
dtype
=
'float32'
)
result
=
fluid
.
layers
.
lod_append
(
x
,
[
0
,
2
,
6
])
level
=
fluid
.
layers
.
data
(
name
=
'level'
,
shape
=
[
3
],
dtype
=
'int32'
,
lod_level
=
0
)
result
=
fluid
.
layers
.
lod_append
(
x
,
level
)
x_i
=
np
.
array
([
1.0
,
1.0
,
1.0
,
1.0
,
1.0
,
1.0
]).
astype
(
"float32"
)
level_i
=
np
.
array
([
0
,
2
,
6
]).
astype
(
"int32"
)
for
use_cuda
in
[
False
,
True
]:
if
use_cuda
and
not
fluid
.
core
.
is_compiled_with_cuda
():
...
...
@@ -39,49 +42,38 @@ class TestLoDAppendAPI(unittest.TestCase):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
[
out
]
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
'x'
:
x_i
},
feed
=
{
'x'
:
x_i
,
'level'
:
level_i
},
fetch_list
=
[
result
],
return_numpy
=
False
)
self
.
assertEqual
(
out
.
recursive_sequence_lengths
(),
[[
2
,
4
]])
class
TestLodAppendOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
()):
def
test_error
(
self
):
# The input(x) must be Variable.
x1
=
np
.
array
([
0.9383
,
0.1983
,
3.2
,
1.2
]).
astype
(
"float64"
)
level1
=
[
0
,
2
,
4
]
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_append
,
x1
,
level1
)
def
test_x_Variable
():
# The input(x) must be Variable.
x1
=
np
.
array
([
0.9383
,
0.1983
,
3.2
,
1.2
]).
astype
(
"float64"
)
level1
=
[
0
,
2
,
4
]
fluid
.
layers
.
lod_append
(
x1
,
level1
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_append
,
x1
,
level1
)
#The input(level) must be Variable or list.
x2
=
fluid
.
layers
.
data
(
name
=
'x2'
,
shape
=
[
4
],
dtype
=
'float32'
)
self
.
assertRaises
(
ValueError
,
fluid
.
layers
.
lod_append
,
x2
,
2
)
def
test_level_Variable
():
# The input(level) must be Variable or list.
x2
=
fluid
.
layers
.
data
(
name
=
'x2'
,
shape
=
[
4
],
dtype
=
'float32'
)
level2
=
2
fluid
.
layers
.
lod_append
(
x2
,
level2
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_append
,
x2
,
level2
)
# Input(x) dtype must be float32 or float64 or int32 or int64
for
dtype
in
[
"bool"
,
"float16"
]:
x3
=
fluid
.
layers
.
data
(
name
=
'x3_'
+
dtype
,
shape
=
[
4
],
dtype
=
dtype
)
level3
=
fluid
.
layers
.
data
(
name
=
'level3'
+
dtype
,
shape
=
[
4
],
dtype
=
'int32'
,
lod_level
=
2
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_append
,
x3
,
level3
)
def
test_x_dtype
():
for
dtype
in
[
"bool"
,
"float16"
]:
x3
=
fluid
.
layers
.
data
(
name
=
'x3_'
+
dtype
,
shape
=
[
4
],
dtype
=
dtype
)
level3
=
fluid
.
layers
.
data
(
name
=
'level3'
,
shape
=
[
4
],
dtype
=
'int32'
,
lod_level
=
2
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_append
,
x3
,
level3
)
def
test_level_dtype
():
for
dtype
in
[
"bool"
,
"float16"
,
"float32"
,
"float64"
,
"int64"
]:
x4
=
fluid
.
layers
.
data
(
name
=
'x4_'
+
dtype
,
shape
=
[
4
],
dtype
=
'float32'
)
level4
=
fluid
.
layers
.
data
(
name
=
'level4'
,
shape
=
[
4
],
dtype
=
dtype
,
lod_level
=
0
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_append
,
x4
,
level4
)
# Input(level) dtype must be int32 when lod_level=0
for
dtype
in
[
"bool"
,
"float16"
,
"float32"
,
"float64"
,
"int64"
]:
x4
=
fluid
.
layers
.
data
(
name
=
'x4'
+
dtype
,
shape
=
[
4
],
dtype
=
'float32'
)
level4
=
fluid
.
layers
.
data
(
name
=
'level4_'
+
dtype
,
shape
=
[
4
],
dtype
=
dtype
,
lod_level
=
0
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_append
,
x4
,
level4
)
if
__name__
==
"__main__"
:
...
...
python/paddle/fluid/tests/unittests/test_lod_reset_op.py
浏览文件 @
62e647c3
...
...
@@ -16,6 +16,7 @@ from __future__ import print_function
import
unittest
import
numpy
as
np
import
paddle.fluid
as
fluid
from
op_test
import
OpTest
from
paddle.fluid
import
Program
,
program_guard
...
...
@@ -136,28 +137,26 @@ class TestLodAppendOpByAttr(OpTest):
class
TestLodResetOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
def
test_Variable
():
# The input must be Variable.
x1
=
fluid
.
create_lod_tensor
(
np
.
ones
([
6
]),
[
3
,
3
],
fluid
.
CPUPlace
())
y1
=
fluid
.
create_lod_tensor
(
np
.
ones
([
6
]),
[
2
,
2
,
2
],
fluid
.
CPUPlace
())
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_reset
,
[
x1
,
y1
])
def
test_type
():
# dtype must be float32 or float64 or int32 or int64
x2
=
fluid
.
layers
.
data
(
shape
=
[
4
],
dtype
=
'uint8'
,
name
=
'x2'
)
# The input must be Variable.
x1
=
np
.
array
([
0.9383
,
0.1983
,
3.2
,
1.2
]).
astype
(
"float64"
)
target_lod
=
[
2
,
2
]
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_reset
,
x1
,
target_lod
)
# Input(x) dtype must be float32 or float64 or int32 or int64
for
dtype
in
[
"bool"
,
"float16"
]:
x2
=
fluid
.
layers
.
data
(
name
=
'x2'
+
dtype
,
shape
=
[
4
],
dtype
=
dtype
)
y2
=
fluid
.
layers
.
data
(
shape
=
[
4
],
dtype
=
'uint8'
,
name
=
'x
2'
,
lod_level
=
2
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_reset
,
[
x2
,
y2
]
)
name
=
'y2'
+
dtype
,
shape
=
[
4
],
dtype
=
'int3
2'
,
lod_level
=
2
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_reset
,
x2
,
y2
)
def
test_type2
():
# dtype must be int32 or int64
x3
=
fluid
.
layers
.
data
(
shape
=
[
4
],
dtype
=
'float32'
,
name
=
'x3'
)
# Input(y) dtype must be int32 when lod_level=0
for
dtype
in
[
"bool"
,
"float16"
,
"float32"
,
"float64"
,
"int64"
]:
x3
=
fluid
.
layers
.
data
(
name
=
'x3'
+
dtype
,
shape
=
[
4
],
dtype
=
'float32'
)
y3
=
fluid
.
layers
.
data
(
shape
=
[
4
],
dtype
=
'float32'
,
name
=
'x3'
,
lod_level
=
0
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_reset
,
[
x3
,
y3
]
)
name
=
'y3'
+
dtype
,
shape
=
[
4
],
dtype
=
dtype
,
lod_level
=
0
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
lod_reset
,
x3
,
y3
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录