Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e5bad90b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
e5bad90b
编写于
9月 22, 2017
作者:
S
superjom
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some enforce change
上级
b545b5b8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
15 deletion
+33
-15
paddle/framework/lod_tensor.cc
paddle/framework/lod_tensor.cc
+18
-8
paddle/framework/lod_tensor.h
paddle/framework/lod_tensor.h
+15
-7
未找到文件。
paddle/framework/lod_tensor.cc
浏览文件 @
e5bad90b
...
@@ -72,20 +72,30 @@ bool operator==(const LoD& a, const LoD& b) {
...
@@ -72,20 +72,30 @@ bool operator==(const LoD& a, const LoD& b) {
return
true
;
return
true
;
}
}
size_t
LoDTensor
::
NumElements
(
size_t
level
,
size_t
idx
)
const
{
PADDLE_ENFORCE_LT
(
level
,
NumLevels
());
PADDLE_ENFORCE_LT
(
idx
,
NumElements
(
level
));
// the last level of LoD, just return number of records in Tensor
if
(
level
==
NumLevels
()
-
1
)
{
}
// high level of LoD, and there is another lower level, return number of
// lower-level elements
}
void
LoDTensor
::
SliceLevels
(
size_t
level_begin
,
size_t
level_end
)
{
void
LoDTensor
::
SliceLevels
(
size_t
level_begin
,
size_t
level_end
)
{
auto
new_lod
=
framework
::
SliceLevels
(
lod_
,
level_begin
,
level_end
);
auto
new_lod
=
framework
::
SliceLevels
(
lod_
,
level_begin
,
level_end
);
lod_
=
new_lod
;
lod_
=
new_lod
;
}
}
void
LoDTensor
::
SliceInLevel
(
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
void
LoDTensor
::
SliceInLevel
(
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
PADDLE_ENFORCE
(
level
<
NumLevels
(),
"level [%d] out of range [%d]"
,
level
,
PADDLE_ENFORCE
_LT
(
level
,
NumLevels
(),
"level [%d] out of range [%d]"
,
level
,
NumLevels
());
NumLevels
());
PADDLE_ENFORCE
(
elem_begin
<
NumElements
(
level
),
PADDLE_ENFORCE
_LT
(
elem_begin
,
NumElements
(
level
),
"element begin [%d] out of range [%d]"
,
elem_begin
,
"element begin [%d] out of range [%d]"
,
elem_begin
,
NumElements
(
level
));
NumElements
(
level
));
PADDLE_ENFORCE
(
elem_end
<
NumElements
(
level
)
+
1
,
PADDLE_ENFORCE
_LT
(
elem_end
,
NumElements
(
level
)
+
1
,
"element end [%d] out of range [%d]"
,
elem_end
,
"element end [%d] out of range [%d]"
,
elem_end
,
NumElements
(
level
));
NumElements
(
level
));
auto
new_lod
=
framework
::
SliceInLevel
(
lod_
,
level
,
elem_begin
,
elem_end
);
auto
new_lod
=
framework
::
SliceInLevel
(
lod_
,
level
,
elem_begin
,
elem_end
);
lod_
=
new_lod
;
lod_
=
new_lod
;
...
...
paddle/framework/lod_tensor.h
浏览文件 @
e5bad90b
...
@@ -65,11 +65,8 @@ class LoDTensor : public Tensor {
...
@@ -65,11 +65,8 @@ class LoDTensor : public Tensor {
* Get a element from LoD.
* Get a element from LoD.
*/
*/
size_t
lod_element
(
size_t
level
,
size_t
elem
)
const
{
size_t
lod_element
(
size_t
level
,
size_t
elem
)
const
{
PADDLE_ENFORCE
(
level
<
NumLevels
(),
"level [%d] out of range [%d]"
,
level
,
PADDLE_ENFORCE_LT
(
level
,
NumLevels
());
NumLevels
());
PADDLE_ENFORCE_LT
(
elem
,
NumElements
(
level
));
PADDLE_ENFORCE
(
elem
<
NumElements
(
level
),
"element begin [%d] out of range [%d]"
,
elem
,
NumElements
(
level
));
return
(
lod_
)[
level
][
elem
];
return
(
lod_
)[
level
][
elem
];
}
}
...
@@ -82,12 +79,23 @@ class LoDTensor : public Tensor {
...
@@ -82,12 +79,23 @@ class LoDTensor : public Tensor {
* Number of elements in a level.
* Number of elements in a level.
*/
*/
size_t
NumElements
(
size_t
level
=
0
)
const
{
size_t
NumElements
(
size_t
level
=
0
)
const
{
PADDLE_ENFORCE
(
level
<
NumLevels
(),
"level [%d] out of range [%d]"
,
level
,
PADDLE_ENFORCE_LT
(
level
,
NumLevels
());
NumLevels
());
// the last offset is the end of last element
// the last offset is the end of last element
return
(
lod_
)[
level
].
size
()
-
1
;
return
(
lod_
)[
level
].
size
()
-
1
;
}
}
/*
* Number of lower-level elements.
* For example, a 2-level lod-tensor
*
* 0-th level | |
* 1-th level || |||
*
* NumElements(0, 0) get 2
* NumElements(0, 1) get 3
*/
size_t
NumElements
(
size_t
level
,
size_t
idx
)
const
;
/*
/*
* Slice of levels[level_begin:level_end]
* Slice of levels[level_begin:level_end]
*/
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录