Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
219f46ae
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看板
提交
219f46ae
编写于
10月 16, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
export SelectedRows to Python
上级
4df6cf4d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
0 deletion
+54
-0
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+17
-0
python/paddle/v2/framework/tests/test_selected_rows.py
python/paddle/v2/framework/tests/test_selected_rows.py
+37
-0
未找到文件。
paddle/pybind/pybind.cc
浏览文件 @
219f46ae
...
@@ -17,6 +17,7 @@ limitations under the License. */
...
@@ -17,6 +17,7 @@ limitations under the License. */
#include "paddle/framework/backward.h"
#include "paddle/framework/backward.h"
#include "paddle/framework/executor.h"
#include "paddle/framework/executor.h"
#include "paddle/framework/lod_tensor.h"
#include "paddle/framework/lod_tensor.h"
#include "paddle/framework/selected_rows.h"
#include "paddle/framework/tensor_array.h"
#include "paddle/framework/tensor_array.h"
#include "paddle/operators/cond_op.h"
#include "paddle/operators/cond_op.h"
#include "paddle/operators/dynamic_recurrent_op.h"
#include "paddle/operators/dynamic_recurrent_op.h"
...
@@ -138,6 +139,22 @@ PYBIND11_PLUGIN(core) {
...
@@ -138,6 +139,22 @@ PYBIND11_PLUGIN(core) {
#endif
#endif
});
});
py
::
class_
<
SelectedRows
>
(
m
,
"SelectedRows"
)
.
def
(
"__init__"
,
[](
SelectedRows
&
instance
)
{
new
(
&
instance
)
SelectedRows
();
})
.
def
(
"__init__"
,
[](
SelectedRows
&
instance
,
const
std
::
vector
<
int64_t
>
rows
,
const
int64_t
&
height
)
{
new
(
&
instance
)
SelectedRows
(
rows
,
height
);
})
.
def
(
"get_tensor"
,
[](
SelectedRows
&
self
)
{
return
self
.
mutable_value
();
},
py
::
return_value_policy
::
reference
)
.
def
(
"set_height"
,
&
SelectedRows
::
set_height
)
.
def
(
"height"
,
&
SelectedRows
::
height
)
.
def
(
"set_rows"
,
&
SelectedRows
::
set_rows
)
.
def
(
"rows"
,
&
SelectedRows
::
rows
,
py
::
return_value_policy
::
reference
);
py
::
class_
<
Variable
>
(
m
,
"Variable"
,
R"DOC(Variable Class.
py
::
class_
<
Variable
>
(
m
,
"Variable"
,
R"DOC(Variable Class.
All parameter, weight, gradient are variables in Paddle.
All parameter, weight, gradient are variables in Paddle.
...
...
python/paddle/v2/framework/tests/test_selected_rows.py
0 → 100644
浏览文件 @
219f46ae
import
paddle.v2.framework.core
as
core
import
unittest
import
numpy
as
np
class
TestSelectedRows
(
unittest
.
TestCase
):
def
test_selected_rows
(
self
):
place
=
core
.
CPUPlace
()
height
=
10
rows
=
[
0
,
4
,
7
]
row_numel
=
10
selcted_rows
=
core
.
SelectedRows
(
rows
,
row_numel
)
np_array
=
np
.
ones
((
len
(
rows
),
height
)).
astype
(
"float32"
)
np_array
[
0
,
0
]
=
2.0
np_array
[
2
,
8
]
=
4.0
tensor
=
selcted_rows
.
get_tensor
()
tensor
.
set
(
np_array
,
place
)
# compare rows
self
.
assertEqual
(
0
,
selcted_rows
.
rows
()[
0
])
self
.
assertEqual
(
4
,
selcted_rows
.
rows
()[
1
])
self
.
assertEqual
(
7
,
selcted_rows
.
rows
()[
2
])
# compare height
self
.
assertEqual
(
10
,
selcted_rows
.
height
())
# compare tensor
self
.
assertAlmostEqual
(
2.0
,
selcted_rows
.
get_tensor
().
get_float_element
(
0
))
self
.
assertAlmostEqual
(
1.0
,
selcted_rows
.
get_tensor
().
get_float_element
(
1
))
self
.
assertAlmostEqual
(
4.0
,
selcted_rows
.
get_tensor
().
get_float_element
(
2
*
row_numel
+
8
))
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录