Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
a43eee40
P
Paddle
项目概览
机器未来
/
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看板
提交
a43eee40
编写于
3月 13, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
92e2207e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
14 addition
and
15 deletion
+14
-15
python/paddle/fluid/tests/unittests/test_lookup_table_op.py
python/paddle/fluid/tests/unittests/test_lookup_table_op.py
+14
-15
未找到文件。
python/paddle/fluid/tests/unittests/test_lookup_table_op.py
浏览文件 @
a43eee40
...
@@ -53,18 +53,11 @@ class TestLookupTableIdsIsSelectedRows(OpTest):
...
@@ -53,18 +53,11 @@ class TestLookupTableIdsIsSelectedRows(OpTest):
def
check_with_place
(
self
,
place
):
def
check_with_place
(
self
,
place
):
scope
=
core
.
Scope
()
scope
=
core
.
Scope
()
# create and initialize
Grad
Variable
# create and initialize Variable
height
=
10
height
=
10
rows
=
[
0
,
4
,
4
,
7
]
rows
=
[
0
,
4
,
4
,
7
]
row_numel
=
12
row_numel
=
12
ids_selected_rows
=
scope
.
var
(
'Ids'
).
get_selected_rows
()
ids_selected_rows
.
set_height
(
height
)
ids_selected_rows
.
set_rows
(
rows
)
np_array
=
np
.
ones
((
len
(
rows
),
row_numel
)).
astype
(
"float32"
)
ids_tensor
=
ids_selected_rows
.
get_tensor
()
ids_tensor
.
set
(
np_array
,
place
)
# create and initialize W Variable
# create and initialize W Variable
W
=
scope
.
var
(
'W'
).
get_tensor
()
W
=
scope
.
var
(
'W'
).
get_tensor
()
W_array
=
np
.
full
((
height
,
row_numel
),
1.0
).
astype
(
"float32"
)
W_array
=
np
.
full
((
height
,
row_numel
),
1.0
).
astype
(
"float32"
)
...
@@ -72,20 +65,26 @@ class TestLookupTableIdsIsSelectedRows(OpTest):
...
@@ -72,20 +65,26 @@ class TestLookupTableIdsIsSelectedRows(OpTest):
W_array
[
i
]
*=
i
W_array
[
i
]
*=
i
W
.
set
(
W_array
,
place
)
W
.
set
(
W_array
,
place
)
# create and initialize Ids Variable
ids_selected_rows
=
scope
.
var
(
'Ids'
).
get_selected_rows
()
ids_selected_rows
.
set_height
(
len
(
rows
))
ids_selected_rows
.
set_rows
(
rows
)
np_array
=
np
.
ones
((
len
(
rows
),
row_numel
)).
astype
(
"float32"
)
ids_tensor
=
ids_selected_rows
.
get_tensor
()
ids_tensor
.
set
(
np_array
,
place
)
# create Out Variable
Out
=
scope
.
var
(
'Out'
).
get_selected_rows
()
Out
=
scope
.
var
(
'Out'
).
get_selected_rows
()
Out_array
=
np
.
full
((
len
(
rows
),
row_numel
),
-
1.0
).
astype
(
"float32"
)
Out
.
set_height
(
height
)
Out
.
set_rows
(
rows
)
Out_tensor
=
Out
.
get_tensor
()
Out_tensor
.
set
(
Out_array
,
place
)
# create and run
concat_rows_op
operator
# create and run
lookup_table
operator
concat_rows_op
=
Operator
(
"lookup_table"
,
W
=
'W'
,
Ids
=
'Ids'
,
Out
=
'Out'
)
concat_rows_op
=
Operator
(
"lookup_table"
,
W
=
'W'
,
Ids
=
'Ids'
,
Out
=
'Out'
)
concat_rows_op
.
run
(
scope
,
place
)
concat_rows_op
.
run
(
scope
,
place
)
# get and compare result
# get result from Out
Out_tensor
=
Out
.
get_tensor
()
result_array
=
np
.
array
(
Out_tensor
)
result_array
=
np
.
array
(
Out_tensor
)
# all(): return True if all elements of the iterable are true (or if the iterable is empty)
for
idx
,
row
in
enumerate
(
rows
):
for
idx
,
row
in
enumerate
(
rows
):
assert
(
row
==
result_array
[
idx
]).
all
()
assert
(
row
==
result_array
[
idx
]).
all
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录