Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
c0523f24
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看板
提交
c0523f24
编写于
9月 06, 2017
作者:
Y
Yan Chunwei
提交者:
GitHub
9月 06, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename LOD to LoD for short of "Level of Details" (#3936)
上级
22826242
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
31 deletion
+31
-31
paddle/framework/lod_tensor.cc
paddle/framework/lod_tensor.cc
+8
-8
paddle/framework/lod_tensor.h
paddle/framework/lod_tensor.h
+13
-13
paddle/framework/lod_tensor_test.cc
paddle/framework/lod_tensor_test.cc
+10
-10
未找到文件。
paddle/framework/lod_tensor.cc
浏览文件 @
c0523f24
...
...
@@ -19,8 +19,8 @@
namespace
paddle
{
namespace
framework
{
L
OD
SliceLevels
(
const
LO
D
&
in
,
size_t
level_begin
,
size_t
level_end
)
{
L
O
D
new_lod
;
L
oD
SliceLevels
(
const
Lo
D
&
in
,
size_t
level_begin
,
size_t
level_end
)
{
L
o
D
new_lod
;
new_lod
.
reserve
(
level_end
-
level_begin
);
for
(
size_t
i
=
level_begin
;
i
<
level_end
;
i
++
)
{
new_lod
.
emplace_back
(
in
.
at
(
i
));
...
...
@@ -28,10 +28,10 @@ LOD SliceLevels(const LOD& in, size_t level_begin, size_t level_end) {
return
new_lod
;
}
L
OD
SliceInLevel
(
const
LO
D
&
in
,
size_t
level
,
size_t
elem_begin
,
L
oD
SliceInLevel
(
const
Lo
D
&
in
,
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
// slice the lod.
L
O
D
new_lod
;
L
o
D
new_lod
;
new_lod
.
reserve
(
in
.
size
()
-
level
);
auto
start
=
in
.
at
(
level
)[
elem_begin
];
auto
end
=
in
.
at
(
level
)[
elem_end
];
...
...
@@ -46,13 +46,13 @@ LOD SliceInLevel(const LOD& in, size_t level, size_t elem_begin,
std
::
transform
(
new_lod
.
back
().
begin
(),
new_lod
.
back
().
end
(),
new_lod
.
back
().
begin
(),
[
start
](
int
v
)
{
return
v
-
start
;
});
PADDLE_ENFORCE_EQ
(
new_lod
.
back
().
front
(),
0
,
"error in slice L
O
D"
);
PADDLE_ENFORCE_EQ
(
new_lod
.
back
().
front
(),
0
,
"error in slice L
o
D"
);
}
PADDLE_ENFORCE_LE
(
new_lod
.
size
(),
in
.
size
());
return
new_lod
;
}
bool
operator
==
(
const
L
OD
&
a
,
const
LO
D
&
b
)
{
bool
operator
==
(
const
L
oD
&
a
,
const
Lo
D
&
b
)
{
if
(
a
.
size
()
!=
b
.
size
())
{
return
false
;
}
...
...
@@ -72,12 +72,12 @@ bool operator==(const LOD& a, const LOD& b) {
return
true
;
}
void
L
O
DTensor
::
SliceLevels
(
size_t
level_begin
,
size_t
level_end
)
{
void
L
o
DTensor
::
SliceLevels
(
size_t
level_begin
,
size_t
level_end
)
{
auto
new_lod
=
framework
::
SliceLevels
(
lod_
,
level_begin
,
level_end
);
lod_
=
new_lod
;
}
void
L
O
DTensor
::
SliceInLevel
(
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
void
L
o
DTensor
::
SliceInLevel
(
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
PADDLE_ENFORCE
(
level
<
NumLevels
(),
"level [%d] out of range [%d]"
,
level
,
NumLevels
());
PADDLE_ENFORCE
(
elem_begin
<
NumElements
(
level
),
...
...
paddle/framework/lod_tensor.h
浏览文件 @
c0523f24
...
...
@@ -35,34 +35,34 @@ template <typename T>
using
Vector
=
thrust
::
host_vector
<
T
>
;
#endif
using
L
O
D
=
std
::
vector
<
Vector
<
size_t
>>
;
using
L
o
D
=
std
::
vector
<
Vector
<
size_t
>>
;
L
OD
SliceLevels
(
const
LO
D
&
in
,
size_t
level_begin
,
size_t
level_end
);
L
oD
SliceLevels
(
const
Lo
D
&
in
,
size_t
level_begin
,
size_t
level_end
);
L
OD
SliceInLevel
(
const
LO
D
&
in
,
size_t
level
,
size_t
elem_begin
,
L
oD
SliceInLevel
(
const
Lo
D
&
in
,
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
);
bool
operator
==
(
const
L
OD
&
a
,
const
LO
D
&
b
);
bool
operator
==
(
const
L
oD
&
a
,
const
Lo
D
&
b
);
/*
* L
O
DTensor (Level of details Tensor)
* L
o
DTensor (Level of details Tensor)
* see https://en.wikipedia.org/wiki/Level_of_details for reference.
*/
class
L
O
DTensor
{
class
L
o
DTensor
{
public:
L
O
DTensor
()
{}
L
ODTensor
(
const
LO
D
&
lod
,
Tensor
*
t
)
:
lod_
(
lod
),
tensor_
(
t
)
{}
L
o
DTensor
()
{}
L
oDTensor
(
const
Lo
D
&
lod
,
Tensor
*
t
)
:
lod_
(
lod
),
tensor_
(
t
)
{}
void
set_lod
(
const
L
O
D
&
lod
)
{
lod_
=
lod
;
}
void
set_lod
(
const
L
o
D
&
lod
)
{
lod_
=
lod
;
}
void
set_tensor
(
Tensor
*
tensor
)
{
tensor_
=
tensor
;
}
Tensor
&
tensor
()
{
return
*
tensor_
;
}
L
O
D
lod
()
{
return
lod_
;
}
L
o
D
lod
()
{
return
lod_
;
}
/*
* Get a element from L
O
D.
* Get a element from L
o
D.
*/
size_t
lod_element
(
size_t
level
,
size_t
elem
)
const
{
PADDLE_ENFORCE
(
level
<
NumLevels
(),
"level [%d] out of range [%d]"
,
level
,
...
...
@@ -74,7 +74,7 @@ class LODTensor {
}
/*
* Number of L
O
DTensor's levels, each level has units of data, for example,
* Number of L
o
DTensor's levels, each level has units of data, for example,
* in the sentence's view, article, paragraph, sentence are 3 levels.
*/
size_t
NumLevels
()
const
{
return
lod_
.
size
();
}
...
...
@@ -100,7 +100,7 @@ class LODTensor {
void
SliceInLevel
(
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
);
private:
L
O
D
lod_
;
L
o
D
lod_
;
Tensor
*
tensor_
;
// not owned
};
}
// namespace framework
...
...
paddle/framework/lod_tensor_test.cc
浏览文件 @
c0523f24
...
...
@@ -21,7 +21,7 @@
namespace
paddle
{
namespace
framework
{
class
L
O
DTensorTester
:
public
::
testing
::
Test
{
class
L
o
DTensorTester
:
public
::
testing
::
Test
{
public:
virtual
void
SetUp
()
override
{
// tensor's batch_size: 30
...
...
@@ -29,7 +29,7 @@ class LODTensorTester : public ::testing::Test {
// 0 10 20
// 0 5 10 15 20
// 0 2 5 7 10 12 15 20
L
O
D
lod
;
L
o
D
lod
;
lod
.
push_back
(
std
::
vector
<
size_t
>
{
0
,
10
,
20
});
lod
.
push_back
(
std
::
vector
<
size_t
>
{
0
,
5
,
10
,
15
,
20
});
lod
.
push_back
(
std
::
vector
<
size_t
>
{
0
,
2
,
5
,
7
,
10
,
12
,
15
,
17
,
20
});
...
...
@@ -47,21 +47,21 @@ class LODTensorTester : public ::testing::Test {
protected:
platform
::
CPUPlace
place
;
Tensor
tensor
;
L
O
DTensor
lod_tensor
;
L
o
DTensor
lod_tensor
;
};
TEST_F
(
L
O
DTensorTester
,
NumLevels
)
{
ASSERT_EQ
(
lod_tensor
.
NumLevels
(),
3UL
);
}
TEST_F
(
L
o
DTensorTester
,
NumLevels
)
{
ASSERT_EQ
(
lod_tensor
.
NumLevels
(),
3UL
);
}
TEST_F
(
L
O
DTensorTester
,
NumElements
)
{
TEST_F
(
L
o
DTensorTester
,
NumElements
)
{
ASSERT_EQ
(
lod_tensor
.
NumElements
(
0
),
2UL
);
ASSERT_EQ
(
lod_tensor
.
NumElements
(
1
),
4UL
);
ASSERT_EQ
(
lod_tensor
.
NumElements
(
2
),
8UL
);
}
TEST_F
(
L
O
DTensorTester
,
SliceLevels
)
{
TEST_F
(
L
o
DTensorTester
,
SliceLevels
)
{
// slice 1 level
for
(
size_t
level
=
0
;
level
<
3UL
;
++
level
)
{
L
O
DTensor
new_lod_tensor
=
lod_tensor
;
L
o
DTensor
new_lod_tensor
=
lod_tensor
;
new_lod_tensor
.
SliceLevels
(
level
,
level
+
1
);
ASSERT_EQ
(
new_lod_tensor
.
NumLevels
(),
1UL
);
ASSERT_EQ
(
new_lod_tensor
.
NumElements
(
0
),
lod_tensor
.
NumElements
(
level
));
...
...
@@ -70,7 +70,7 @@ TEST_F(LODTensorTester, SliceLevels) {
}
// slice 2 level
for
(
size_t
level
=
0
;
level
<
2UL
;
++
level
)
{
L
O
DTensor
new_lod_tensor
=
lod_tensor
;
L
o
DTensor
new_lod_tensor
=
lod_tensor
;
new_lod_tensor
.
SliceLevels
(
level
,
level
+
2
);
ASSERT_EQ
(
new_lod_tensor
.
NumLevels
(),
2UL
);
ASSERT_EQ
(
new_lod_tensor
.
NumElements
(
0
),
lod_tensor
.
NumElements
(
level
));
...
...
@@ -80,9 +80,9 @@ TEST_F(LODTensorTester, SliceLevels) {
}
}
TEST_F
(
L
O
DTensorTester
,
SliceInLevel
)
{
TEST_F
(
L
o
DTensorTester
,
SliceInLevel
)
{
size_t
level
=
0
;
L
O
DTensor
new_lod_tensor
=
lod_tensor
;
L
o
DTensor
new_lod_tensor
=
lod_tensor
;
new_lod_tensor
.
SliceInLevel
(
level
,
0
,
2
);
EXPECT_EQ
(
new_lod_tensor
.
NumLevels
(),
3UL
);
EXPECT_EQ
(
new_lod_tensor
.
NumElements
(
0
),
2UL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录