Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
TonyTonyFun
Paddle
提交
14253875
P
Paddle
项目概览
TonyTonyFun
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
14253875
编写于
8月 16, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Using unique_ptr instead of raw ptr
Fit google C++ style
上级
a0d77533
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
14 addition
and
13 deletion
+14
-13
paddle/framework/operator.h
paddle/framework/operator.h
+6
-4
paddle/framework/operator_test.cc
paddle/framework/operator_test.cc
+1
-2
paddle/operators/net_op.cc
paddle/operators/net_op.cc
+3
-3
paddle/operators/net_op.h
paddle/operators/net_op.h
+2
-1
paddle/operators/net_op_test.cc
paddle/operators/net_op_test.cc
+2
-3
未找到文件。
paddle/framework/operator.h
浏览文件 @
14253875
...
...
@@ -112,8 +112,8 @@ class OperatorBase {
const
AttributeMap
&
Attrs
()
const
{
return
attrs_
;
}
// Return a new operator instance, which is as same as this.
//
NOTE: It is caller's responsibility to delete that operator instance
.
virtual
OperatorBase
*
Clone
()
const
=
0
;
//
Use unique_ptr to prevent caller forget to delete this pointer
.
virtual
std
::
unique_ptr
<
OperatorBase
>
Clone
()
const
=
0
;
public:
std
::
string
type_
;
...
...
@@ -133,7 +133,9 @@ class OperatorBase {
// If you are writing an kernel operator, `Clone` will be defined when you
// register it.
#define DEFINE_OP_CLONE_METHOD(CLS) \
OperatorBase* Clone() const final { return new CLS(*this); }
std::unique_ptr<OperatorBase> Clone() const final { \
return std::unique_ptr<OperatorBase>(new CLS(*this)); \
}
// Macro for define a default constructor for Operator.
// You can also use
...
...
paddle/framework/operator_test.cc
浏览文件 @
14253875
...
...
@@ -257,7 +257,6 @@ class OperatorClone : public paddle::framework::OperatorBase {
TEST
(
Operator
,
Clone
)
{
OperatorClone
a
(
"ABC"
,
{},
{},
{});
auto
*
b
=
a
.
Clone
();
auto
b
=
a
.
Clone
();
ASSERT_EQ
(
a
.
Type
(),
b
->
Type
());
delete
b
;
}
\ No newline at end of file
paddle/operators/net_op.cc
浏览文件 @
14253875
...
...
@@ -85,13 +85,13 @@ NetOp::NetOp(const std::string& type,
const
framework
::
OperatorBase
::
VarNameMap
&
inputs
,
const
framework
::
OperatorBase
::
VarNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{}
:
framework
::
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{}
framework
::
OperatorBase
*
NetOp
::
Clone
()
const
{
std
::
unique_ptr
<
framework
::
OperatorBase
>
NetOp
::
Clone
()
const
{
PADDLE_ENFORCE
(
add_op_done_
,
"Must clone a sealed NetOp, invoke Net::CompleteAddOp before clone"
);
return
new
NetOp
(
*
this
);
return
std
::
unique_ptr
<
OperatorBase
>
(
new
NetOp
(
*
this
)
);
}
}
// namespace operators
...
...
paddle/operators/net_op.h
浏览文件 @
14253875
...
...
@@ -109,7 +109,8 @@ class NetOp : public framework::OperatorBase {
bool
IsNetOp
()
const
override
;
std
::
vector
<
std
::
string
>
OutputVars
(
bool
has_intermediate
)
const
override
;
framework
::
OperatorBase
*
Clone
()
const
override
;
std
::
unique_ptr
<
framework
::
OperatorBase
>
Clone
()
const
override
;
std
::
vector
<
std
::
shared_ptr
<
OperatorBase
>>
ops_
;
...
...
paddle/operators/net_op_test.cc
浏览文件 @
14253875
...
...
@@ -84,14 +84,13 @@ TEST(NetOp, Clone) {
net
.
AddOp
(
std
::
shared_ptr
<
EmptyOp
>
(
new
EmptyOp
{
"empty"
,
{},
{},
{}}));
net
.
AddOp
(
std
::
shared_ptr
<
EmptyOp
>
(
new
EmptyOp
{
"empty2"
,
{},
{},
{}}));
net
.
CompleteAddOp
(
true
);
auto
*
new_net_op
=
net
.
Clone
();
auto
new_net_op
=
net
.
Clone
();
ASSERT_NE
(
new_net_op
,
nullptr
);
ASSERT_TRUE
(
new_net_op
->
IsNetOp
());
auto
*
new_net
=
static_cast
<
NetOp
*>
(
new_net_op
);
auto
*
new_net
=
static_cast
<
NetOp
*>
(
new_net_op
.
get
()
);
ASSERT_EQ
(
2
,
new_net
->
ops_
.
size
());
ASSERT_EQ
(
new_net
->
ops_
[
0
]
->
Type
(),
"empty"
);
ASSERT_EQ
(
new_net
->
ops_
[
1
]
->
Type
(),
"empty2"
);
delete
new_net
;
}
}
// namespace operators
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录