Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
fef3654b
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fef3654b
编写于
1月 27, 2021
作者:
L
liu zhengxi
提交者:
GitHub
1月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade gather_tree to core.ops (#30697)
* upgrade gather_tree to core.ops * update gather_tree unittests
上级
f8da5536
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
26 addition
and
11 deletion
+26
-11
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+14
-11
python/paddle/fluid/tests/unittests/test_gather_tree_op.py
python/paddle/fluid/tests/unittests/test_gather_tree_op.py
+12
-0
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
fef3654b
...
...
@@ -15011,6 +15011,9 @@ def gather_tree(ids, parents):
append_batch_size=False)
final_sequences = fluid.layers.gather_tree(ids, parents)
"""
if in_dygraph_mode():
return core.ops.gather_tree(ids, parents)
else:
helper = LayerHelper('gather_tree', **locals())
check_variable_and_dtype(ids, 'ids', ['int32', 'int64'], 'gather_tree')
check_variable_and_dtype(parents, 'parents', ['int32', 'int64'],
...
...
python/paddle/fluid/tests/unittests/test_gather_tree_op.py
浏览文件 @
fef3654b
...
...
@@ -17,6 +17,7 @@ from __future__ import print_function
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.framework
import
program_guard
,
Program
...
...
@@ -52,6 +53,7 @@ class TestGatherTreeOp(OpTest):
class
TestGatherTreeOpAPI
(
unittest
.
TestCase
):
def
test_case
(
self
):
paddle
.
enable_static
()
ids
=
fluid
.
layers
.
data
(
name
=
'ids'
,
shape
=
[
5
,
2
,
2
],
dtype
=
'int64'
,
append_batch_size
=
False
)
parents
=
fluid
.
layers
.
data
(
...
...
@@ -60,10 +62,19 @@ class TestGatherTreeOpAPI(unittest.TestCase):
dtype
=
'int64'
,
append_batch_size
=
False
)
final_sequences
=
fluid
.
layers
.
gather_tree
(
ids
,
parents
)
paddle
.
disable_static
()
def
test_case2
(
self
):
ids
=
paddle
.
to_tensor
(
[[[
2
,
2
],
[
6
,
1
]],
[[
3
,
9
],
[
6
,
1
]],
[[
0
,
1
],
[
9
,
0
]]])
parents
=
paddle
.
to_tensor
(
[[[
0
,
0
],
[
1
,
1
]],
[[
1
,
0
],
[
1
,
0
]],
[[
0
,
0
],
[
0
,
1
]]])
final_sequences
=
paddle
.
nn
.
functional
.
gather_tree
(
ids
,
parents
)
class
TestGatherTreeOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
program_guard
(
Program
(),
Program
()):
ids
=
fluid
.
layers
.
data
(
name
=
'ids'
,
...
...
@@ -111,6 +122,7 @@ class TestGatherTreeOpError(unittest.TestCase):
fluid
.
layers
.
gather_tree
(
ids
,
bad_parents
)
self
.
assertRaises
(
TypeError
,
test_type_parents
)
paddle
.
disable_static
()
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录