Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
89cf4f90
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
89cf4f90
编写于
4月 21, 2020
作者:
myq406450149
提交者:
GitHub
4月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lod_rank_table error message enhance (#23613)
* lod_rank_table error message enhance. test=develop
上级
5c669ad1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
1 deletion
+92
-1
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+6
-0
python/paddle/fluid/tests/unittests/test_lod_rank_table.py
python/paddle/fluid/tests/unittests/test_lod_rank_table.py
+21
-1
python/paddle/fluid/tests/unittests/test_lod_tensor_array_ops.py
...paddle/fluid/tests/unittests/test_lod_tensor_array_ops.py
+65
-0
未找到文件。
python/paddle/fluid/layers/control_flow.py
浏览文件 @
89cf4f90
...
@@ -1140,6 +1140,12 @@ def lod_rank_table(x, level=0):
...
@@ -1140,6 +1140,12 @@ def lod_rank_table(x, level=0):
dtype='float32', lod_level=1)
dtype='float32', lod_level=1)
out = layers.lod_rank_table(x=x, level=0)
out = layers.lod_rank_table(x=x, level=0)
"""
"""
check_type
(
x
,
'x'
,
(
Variable
,
list
),
'lod_rank_table'
)
if
isinstance
(
x
,
(
list
)):
for
i
,
input_x
in
enumerate
(
x
):
check_type
(
input_x
,
'input['
+
str
(
i
)
+
']'
,
Variable
,
'lod_rank_table'
)
helper
=
LayerHelper
(
"lod_rank_table"
,
**
locals
())
helper
=
LayerHelper
(
"lod_rank_table"
,
**
locals
())
table
=
helper
.
create_variable
(
table
=
helper
.
create_variable
(
type
=
core
.
VarDesc
.
VarType
.
LOD_RANK_TABLE
,
type
=
core
.
VarDesc
.
VarType
.
LOD_RANK_TABLE
,
...
...
python/paddle/fluid/tests/unittests/test_lod_rank_table.py
浏览文件 @
89cf4f90
...
@@ -17,7 +17,7 @@ from __future__ import print_function
...
@@ -17,7 +17,7 @@ from __future__ import print_function
from
paddle.fluid.layers
import
data
from
paddle.fluid.layers
import
data
from
paddle.fluid.layers.control_flow
import
lod_rank_table
from
paddle.fluid.layers.control_flow
import
lod_rank_table
from
paddle.fluid.executor
import
Executor
from
paddle.fluid.executor
import
Executor
import
paddle.fluid.core
as
core
from
paddle.fluid
import
Program
,
program_guard
,
core
import
numpy
import
numpy
import
unittest
import
unittest
...
@@ -41,5 +41,25 @@ class TestLoDRankTable(unittest.TestCase):
...
@@ -41,5 +41,25 @@ class TestLoDRankTable(unittest.TestCase):
self
.
assertEqual
([(
0
,
5
),
(
1
,
1
),
(
2
,
1
)],
list
(
table
.
items
()))
self
.
assertEqual
([(
0
,
5
),
(
1
,
1
),
(
2
,
1
)],
list
(
table
.
items
()))
class
TestLoDRankTableError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
x
=
numpy
.
random
.
random
((
2
,
4
)).
astype
(
"float32"
)
def
test_Variable
():
rank_table
=
lod_rank_table
(
x
=
x
,
level
=
1
)
self
.
assertRaises
(
TypeError
,
test_Variable
)
def
test_list_Variable
():
rank_table
=
lod_rank_table
(
x
=
[
x
],
level
=
1
)
self
.
assertRaises
(
TypeError
,
test_list_Variable
)
x
=
data
(
name
=
'x'
,
shape
=
[
10
],
dtype
=
'float32'
,
lod_level
=
1
)
out
=
lod_rank_table
(
x
=
x
,
level
=
0
)
out
=
lod_rank_table
(
x
=
[
x
],
level
=
0
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_lod_tensor_array_ops.py
浏览文件 @
89cf4f90
...
@@ -219,5 +219,70 @@ class TestCPULoDTensorArrayOpGrad(unittest.TestCase):
...
@@ -219,5 +219,70 @@ class TestCPULoDTensorArrayOpGrad(unittest.TestCase):
self
.
assertAlmostEqual
(
1.0
,
g_out_sum
,
delta
=
0.1
)
self
.
assertAlmostEqual
(
1.0
,
g_out_sum
,
delta
=
0.1
)
class
TestLoDTensorArrayError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
x
=
numpy
.
random
.
random
((
10
)).
astype
(
"float32"
)
x2
=
layers
.
data
(
name
=
'x'
,
shape
=
[
10
])
table
=
lod_rank_table
(
x2
,
level
=
0
)
def
test_x_Variable
():
rank_table
=
lod_tensor_to_array
(
x
=
x
,
table
=
table
)
self
.
assertRaises
(
TypeError
,
test_x_Variable
)
table2
=
numpy
.
random
.
random
((
2
)).
astype
(
"int64"
)
def
test_table_Variable
():
rank_table
=
lod_tensor_to_array
(
x
=
x2
,
table
=
table2
)
self
.
assertRaises
(
TypeError
,
test_table_Variable
)
def
test_x_list_Variable
():
rank_table
=
lod_tensor_to_array
(
x
=
[
x
],
table
=
table
)
self
.
assertRaises
(
TypeError
,
test_x_list_Variable
)
def
test_table_list_Variable
():
rank_table
=
lod_tensor_to_array
(
x
=
x2
,
table
=
[
table2
])
self
.
assertRaises
(
TypeError
,
test_table_list_Variable
)
array
=
lod_tensor_to_array
(
x2
,
table
)
class
TestArrayLoDTensorError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
x
=
numpy
.
random
.
random
((
10
)).
astype
(
"float32"
)
x2
=
layers
.
data
(
name
=
'x'
,
shape
=
[
10
])
table
=
lod_rank_table
(
x2
,
level
=
0
)
array
=
lod_tensor_to_array
(
x2
,
table
)
def
test_x_Variable
():
rank_table
=
array_to_lod_tensor
(
x
=
x
,
table
=
table
)
self
.
assertRaises
(
TypeError
,
test_x_Variable
)
table2
=
numpy
.
random
.
random
((
2
)).
astype
(
"int64"
)
def
test_table_Variable
():
rank_table
=
array_to_lod_tensor
(
x
=
array
,
table
=
table2
)
self
.
assertRaises
(
TypeError
,
test_table_Variable
)
def
test_x_list_Variable
():
rank_table
=
array_to_lod_tensor
(
x
=
[
x
],
table
=
table
)
self
.
assertRaises
(
TypeError
,
test_x_list_Variable
)
def
test_table_list_Variable
():
rank_table
=
array_to_lod_tensor
(
x
=
x2
,
table
=
[
table2
])
self
.
assertRaises
(
TypeError
,
test_table_list_Variable
)
array
=
array_to_lod_tensor
(
x2
,
table
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录