Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
dcf4682b
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看板
提交
dcf4682b
编写于
9月 22, 2017
作者:
S
superjom
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add LoDTensor::NumElements(id,id)
上级
d226daee
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
0 deletion
+24
-0
paddle/framework/lod_tensor.cc
paddle/framework/lod_tensor.cc
+6
-0
paddle/framework/lod_tensor.h
paddle/framework/lod_tensor.h
+12
-0
paddle/framework/lod_tensor_test.cc
paddle/framework/lod_tensor_test.cc
+6
-0
未找到文件。
paddle/framework/lod_tensor.cc
浏览文件 @
dcf4682b
...
@@ -77,9 +77,15 @@ size_t LoDTensor::NumElements(size_t level, size_t idx) const {
...
@@ -77,9 +77,15 @@ size_t LoDTensor::NumElements(size_t level, size_t idx) const {
PADDLE_ENFORCE_LT
(
idx
,
NumElements
(
level
));
PADDLE_ENFORCE_LT
(
idx
,
NumElements
(
level
));
// the last level of LoD, just return number of records in Tensor
// the last level of LoD, just return number of records in Tensor
if
(
level
==
NumLevels
()
-
1
)
{
if
(
level
==
NumLevels
()
-
1
)
{
return
lod_
[
level
][
idx
+
1
]
-
lod_
[
level
][
idx
];
}
}
// high level of LoD, and there is another lower level, return number of
// high level of LoD, and there is another lower level, return number of
// lower-level elements
// lower-level elements
auto
tmp
=
SliceInLevel
(
lod_
,
level
,
idx
,
idx
+
1
);
PADDLE_ENFORCE_GE
(
tmp
.
size
(),
2
);
// there is a 0 as a placeholder stored in LoD, so the number of elements
// equals lod.size() - 1
return
tmp
[
1
].
size
()
-
1
;
}
}
void
LoDTensor
::
SliceLevels
(
size_t
level_begin
,
size_t
level_end
)
{
void
LoDTensor
::
SliceLevels
(
size_t
level_begin
,
size_t
level_end
)
{
...
...
paddle/framework/lod_tensor.h
浏览文件 @
dcf4682b
...
@@ -38,6 +38,18 @@ using Vector = thrust::host_vector<
...
@@ -38,6 +38,18 @@ using Vector = thrust::host_vector<
T
,
thrust
::
system
::
cuda
::
experimental
::
pinned_allocator
<
T
>>
;
T
,
thrust
::
system
::
cuda
::
experimental
::
pinned_allocator
<
T
>>
;
#endif
#endif
/*
* 3-level LoD stores
*
* 0 10 20
* 0 5 10 15 20
* 0 2 5 7 10 12 15 20
*
* - in a level, each element indicates offset in the underlying Tensor
* - the first element should be 0 and that indicates that this sequence start
* from 0
* - each sequence's begin and end(no-inclusive) is level[id, id+1]
*/
using
LoD
=
std
::
vector
<
Vector
<
size_t
>>
;
using
LoD
=
std
::
vector
<
Vector
<
size_t
>>
;
LoD
SliceLevels
(
const
LoD
&
in
,
size_t
level_begin
,
size_t
level_end
);
LoD
SliceLevels
(
const
LoD
&
in
,
size_t
level_begin
,
size_t
level_end
);
...
...
paddle/framework/lod_tensor_test.cc
浏览文件 @
dcf4682b
...
@@ -56,6 +56,12 @@ TEST_F(LoDTensorTester, NumElements) {
...
@@ -56,6 +56,12 @@ TEST_F(LoDTensorTester, NumElements) {
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
2
),
8UL
);
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
2
),
8UL
);
}
}
TEST_F
(
LoDTensorTester
,
NumElements2
)
{
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
0
,
0
),
2UL
);
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
0
,
1
),
2UL
);
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
1
,
1
),
2UL
);
}
TEST_F
(
LoDTensorTester
,
SliceLevels
)
{
TEST_F
(
LoDTensorTester
,
SliceLevels
)
{
// slice 1 level
// slice 1 level
for
(
size_t
level
=
0
;
level
<
3UL
;
++
level
)
{
for
(
size_t
level
=
0
;
level
<
3UL
;
++
level
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录