Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
f947c153
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f947c153
编写于
1月 04, 2018
作者:
Y
yangyaming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consider multiple levels of LoD.
上级
66ae0a8c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
4 deletion
+19
-4
paddle/operators/shrink_rnn_memory_op.cc
paddle/operators/shrink_rnn_memory_op.cc
+16
-3
python/paddle/v2/fluid/tests/test_shrink_rnn_memory.py
python/paddle/v2/fluid/tests/test_shrink_rnn_memory.py
+3
-1
未找到文件。
paddle/operators/shrink_rnn_memory_op.cc
浏览文件 @
f947c153
...
...
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/framework/lod_rank_table.h"
#include "paddle/framework/lod_tensor.h"
#include "paddle/operators/array_operator.h"
#include "paddle/operators/math/math_function.h"
...
...
@@ -49,12 +50,24 @@ class ShrinkRNNMemoryOp : public ArrayOp {
// should consider multiple levels
size_t
height
=
dst_num_rows
;
auto
lod_level
=
lod_rank_table
.
level
();
auto
lod_level
=
rank_table
.
level
();
if
(
x_tensor
.
lod
().
size
()
>
lod_level
&&
x_tensor
.
lod
()[
lod_level
].
size
()
<
dst_num_rows
)
{
x_tensor
.
lod
()[
lod_level
].
size
()
>
static_cast
<
size_t
>
(
dst_num_rows
)
)
{
auto
lod_offset
=
framework
::
GetSubLoDAndAbsoluteOffset
(
x_tensor
.
lod
(),
0
,
dst_num_rows
+
1
,
lod_level
);
x_tensor
.
lod
(),
0
,
dst_num_rows
,
lod_level
);
height
=
lod_offset
.
second
.
second
;
auto
out_lod
=
out_tensor
.
mutable_lod
();
auto
x_lod
=
x_tensor
.
lod
();
out_lod
->
reserve
(
lod_level
+
lod_offset
.
first
.
size
());
for
(
size_t
i
=
0
;
i
<
lod_level
;
++
i
)
{
out_lod
->
emplace_back
(
x_lod
.
at
(
i
));
}
framework
::
LoD
remain
;
framework
::
AppendLoD
(
&
remain
,
lod_offset
.
first
);
for
(
size_t
j
=
0
;
j
<
remain
.
size
();
++
j
)
{
out_lod
->
emplace_back
(
remain
[
j
]);
}
}
if
(
dst_num_rows
!=
0
)
{
...
...
python/paddle/v2/fluid/tests/test_shrink_rnn_memory.py
浏览文件 @
f947c153
...
...
@@ -29,7 +29,9 @@ class TestShrinkRNNMemory(unittest.TestCase):
tensor_np
=
numpy
.
random
.
random
(
size
=
(
6
,
100
)).
astype
(
'float32'
)
tensor
.
set
(
tensor_np
,
cpu
)
exe
=
Executor
(
cpu
)
outs
=
exe
.
run
(
feed
=
{
'x'
:
tensor
},
fetch_list
=
[
mem1
,
mem2
,
mem3
])
outs
=
exe
.
run
(
feed
=
{
'x'
:
tensor
},
fetch_list
=
[
mem1
,
mem2
,
mem3
],
return_numpy
=
False
)
self
.
assertTrue
(
numpy
.
allclose
(
tensor_np
[
0
:
6
],
outs
[
0
]))
self
.
assertTrue
(
numpy
.
allclose
(
tensor_np
[
0
:
5
],
outs
[
1
]))
self
.
assertTrue
(
numpy
.
allclose
(
tensor_np
[
0
:
2
],
outs
[
2
]))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录