Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
0edd6cf1
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0edd6cf1
编写于
7月 02, 2020
作者:
石
石晓伟
提交者:
GitHub
7月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update the vector_view, test=develop (#3869)
上级
c6b784d2
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
36 addition
and
9 deletion
+36
-9
lite/model_parser/flatbuffers/vector_view.h
lite/model_parser/flatbuffers/vector_view.h
+25
-6
lite/model_parser/flatbuffers/vector_view_test.cc
lite/model_parser/flatbuffers/vector_view_test.cc
+11
-3
未找到文件。
lite/model_parser/flatbuffers/vector_view.h
浏览文件 @
0edd6cf1
...
...
@@ -18,6 +18,7 @@
#include <type_traits>
#include <vector>
#include "flatbuffers/flatbuffers.h"
#include "lite/utils/cp_logging.h"
namespace
paddle
{
namespace
lite
{
...
...
@@ -32,7 +33,7 @@ struct ElementTraits {
};
template
<
typename
T
>
struct
ElementTraits
<
T
,
struct
ElementTraits
<
T
*
,
typename
std
::
enable_if
<
std
::
is_class
<
T
>::
value
>::
type
>
{
typedef
flatbuffers
::
Offset
<
T
>
element_type
;
};
...
...
@@ -76,6 +77,15 @@ class VectorView {
typename
Traits
::
const_iterator
begin
()
const
{
return
cvec_
->
begin
();
}
typename
Traits
::
const_iterator
end
()
const
{
return
cvec_
->
end
();
}
size_t
size
()
const
{
return
cvec_
->
size
();
}
operator
std
::
vector
<
T
>
()
{
VLOG
(
10
)
<<
"Copying elements out of VectorView will damage performance."
;
std
::
vector
<
T
>
tmp
;
tmp
.
reserve
(
cvec_
->
size
());
for
(
auto
val
:
*
cvec_
)
{
tmp
.
push_back
(
val
);
}
return
tmp
;
}
~
VectorView
()
=
default
;
private:
...
...
@@ -90,22 +100,22 @@ struct FBSStrIterator {
VI
;
explicit
FBSStrIterator
(
const
VI
&
iter
)
{
iter_
=
iter
;
}
const
VI
&
RawI
ter
()
const
{
return
iter_
;
}
const
VI
&
raw_i
ter
()
const
{
return
iter_
;
}
bool
operator
==
(
const
FBSStrIterator
&
other
)
const
{
return
iter_
==
other
.
RawI
ter
();
return
iter_
==
other
.
raw_i
ter
();
}
bool
operator
<
(
const
FBSStrIterator
&
other
)
const
{
return
iter_
<
other
.
RawI
ter
();
return
iter_
<
other
.
raw_i
ter
();
}
bool
operator
!=
(
const
FBSStrIterator
&
other
)
const
{
return
iter_
!=
other
.
RawI
ter
();
return
iter_
!=
other
.
raw_i
ter
();
}
ptrdiff_t
operator
-
(
const
FBSStrIterator
&
other
)
const
{
return
iter_
-
other
.
RawI
ter
();
return
iter_
-
other
.
raw_i
ter
();
}
std
::
string
operator
*
()
const
{
return
iter_
.
operator
*
()
->
str
();
}
...
...
@@ -144,6 +154,15 @@ class VectorView<std::string, Flatbuffers> {
FBSStrIterator
begin
()
const
{
return
FBSStrIterator
(
cvec_
->
begin
());
}
FBSStrIterator
end
()
const
{
return
FBSStrIterator
(
cvec_
->
end
());
}
size_t
size
()
const
{
return
cvec_
->
size
();
}
operator
std
::
vector
<
std
::
string
>
()
{
VLOG
(
10
)
<<
"Copying elements out of VectorView will damage performance."
;
std
::
vector
<
std
::
string
>
tmp
;
tmp
.
reserve
(
cvec_
->
size
());
for
(
auto
val
:
*
cvec_
)
{
tmp
.
push_back
(
val
->
str
());
}
return
tmp
;
}
~
VectorView
()
=
default
;
private:
...
...
lite/model_parser/flatbuffers/vector_view_test.cc
浏览文件 @
0edd6cf1
...
...
@@ -85,15 +85,15 @@ TEST(VectorView, Flatbuffers) {
auto
program
=
fbs
::
proto
::
GetProgramDesc
(
fbb
.
GetBufferPointer
());
// BlockDesc View
VectorView
<
proto
::
BlockDesc
>
block_view
(
program
->
blocks
());
VectorView
<
proto
::
BlockDesc
*
>
block_view
(
program
->
blocks
());
EXPECT_EQ
(
block_view
.
size
(),
static_cast
<
size_t
>
(
2
));
EXPECT_EQ
(
block_view
[
0
]
->
idx
(),
0
);
EXPECT_EQ
(
block_view
[
1
]
->
idx
(),
1
);
// OpDesc & Attr View
VectorView
<
proto
::
OpDesc
>
op_view
(
block_view
[
0
]
->
ops
());
VectorView
<
proto
::
OpDesc
*
>
op_view
(
block_view
[
0
]
->
ops
());
EXPECT_EQ
(
op_view
[
0
]
->
type
()
->
str
(),
std
::
string
(
"hello!"
));
VectorView
<
proto
::
OpDesc_
::
Attr
>
attr_view
(
op_view
[
0
]
->
attrs
());
VectorView
<
proto
::
OpDesc_
::
Attr
*
>
attr_view
(
op_view
[
0
]
->
attrs
());
// int32_t View
VectorView
<
int32_t
>
ints_view
(
attr_view
[
0
]
->
ints
());
...
...
@@ -106,6 +106,10 @@ TEST(VectorView, Flatbuffers) {
for
(
size_t
i
=
0
;
i
<
ints_view
.
size
();
++
i
)
{
EXPECT_EQ
(
ints_view
[
i
],
ints
[
i
]);
}
std
::
vector
<
int32_t
>
ints_2
(
ints_view
);
for
(
size_t
i
=
0
;
i
<
ints_2
.
size
();
++
i
)
{
EXPECT_EQ
(
ints_2
[
i
],
ints
[
i
]);
}
// String View
VectorView
<
std
::
string
>
strings_view
(
attr_view
[
0
]
->
strings
());
...
...
@@ -119,6 +123,10 @@ TEST(VectorView, Flatbuffers) {
for
(
size_t
i
=
0
;
i
<
strings_view
.
size
();
++
i
)
{
EXPECT_EQ
(
strings_view
[
i
],
strings
[
i
]);
}
std
::
vector
<
std
::
string
>
string_2
(
strings_view
);
for
(
size_t
i
=
0
;
i
<
string_2
.
size
();
++
i
)
{
EXPECT_EQ
(
string_2
[
i
],
strings
[
i
]);
}
}
}
// namespace lite
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录