Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5031c93a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
12 个月 前同步成功
通知
2292
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5031c93a
编写于
7月 30, 2017
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass test
上级
c5afddc6
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
22 addition
and
20 deletion
+22
-20
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+3
-1
paddle/framework/scope.cc
paddle/framework/scope.cc
+14
-10
paddle/framework/scope.h
paddle/framework/scope.h
+1
-4
paddle/framework/scope_test.cc
paddle/framework/scope_test.cc
+3
-3
paddle/framework/variable.h
paddle/framework/variable.h
+1
-2
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
5031c93a
...
...
@@ -8,7 +8,9 @@ cc_test(tensor_test SRCS tensor_test.cc DEPS tensor)
cc_test
(
eigen_test SRCS eigen_test.cc DEPS tensor
)
cc_test
(
variable_test SRCS variable_test.cc
)
cc_test
(
scope_test SRCS scope_test.cc
)
cc_library
(
scope SRCS scope.cc
)
cc_test
(
scope_test SRCS scope_test.cc DEPS scope
)
proto_library
(
attr_type SRCS attr_type.proto
)
proto_library
(
op_proto SRCS op_proto.proto DEPS attr_type
)
...
...
paddle/framework/scope.cc
浏览文件 @
5031c93a
...
...
@@ -13,13 +13,13 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/framework/scope.h"
#include "paddle/string/printf.h"
namespace
paddle
{
namespace
framework
{
Scope
::~
Scope
()
{
for
(
Variable
*
v
:
vars_
)
delete
v
;
for
(
auto
&
kv
:
vars_
)
delete
kv
.
second
;
for
(
Scope
*
s
:
kids_
)
delete
s
;
}
...
...
@@ -29,28 +29,32 @@ Scope& Scope::NewScope() {
}
Variable
*
Scope
::
NewVar
(
const
std
::
string
&
name
)
{
a
tu
o
iter
=
vars_
.
find
(
name
);
a
ut
o
iter
=
vars_
.
find
(
name
);
if
(
iter
!=
vars_
.
end
())
{
return
iter
.
second
->
get
()
;
return
iter
->
second
;
}
Variable
*
v
=
new
Variable
();
v
->
name_
=
name
;
v
ar_
[
name
]
=
v
;
v
ars_
[
name
]
=
v
;
v
->
name_
=
&
(
vars_
.
find
(
name
)
->
first
)
;
return
v
;
}
Variable
*
Scope
::
NewVar
()
{
return
NewVar
(
string
.
Sprintf
(
"%p.%d"
,
this
,
vars_
.
size
()));
return
NewVar
(
string
::
Sprintf
(
"%p.%d"
,
this
,
vars_
.
size
()));
}
Variable
*
Scope
::
FindVar
(
const
std
::
string
&
name
)
const
{
auto
it
=
vars_
.
find
(
name
);
if
(
it
!=
vars_
.
end
())
return
it
->
second
.
get
()
;
if
(
it
!=
vars_
.
end
())
return
it
->
second
;
return
(
parent_
==
nullptr
)
?
nullptr
:
parent_
->
FindVar
(
name
);
}
Scope
*
Scope
::
FindScope
(
const
Variable
*
var
)
const
{
if
(
FindVar
(
var
->
name_
)
!=
nullptr
)
return
this
;
Scope
*
Scope
::
FindScope
(
const
Variable
*
var
)
{
for
(
auto
&
kv
:
vars_
)
{
if
(
kv
.
second
==
var
)
{
return
this
;
}
}
return
(
parent_
==
nullptr
)
?
nullptr
:
parent_
->
FindScope
(
var
);
}
...
...
paddle/framework/scope.h
浏览文件 @
5031c93a
...
...
@@ -53,10 +53,7 @@ class Scope {
Variable
*
FindVar
(
const
std
::
string
&
name
)
const
;
// Find the scope or an ancestor scope that contains the given variable.
Scope
*
FindScope
(
const
Variable
*
var
)
const
;
// Returns the name of a variable in this scope.
std
::
string
VarName
(
const
Variable
*
var
)
const
{
return
var
->
name_
;
}
Scope
*
FindScope
(
const
Variable
*
var
);
private:
// Call Scope::NewScope for a sub-scope.
...
...
paddle/framework/scope_test.cc
浏览文件 @
5031c93a
...
...
@@ -49,8 +49,8 @@ TEST(Scope, FindVar) {
TEST
(
Scope
,
FindScope
)
{
Scope
s
;
Scope
&
ss
=
s
.
NewScope
();
s
.
NewVar
(
"a"
);
Variable
*
v
=
s
.
NewVar
(
"a"
);
EXPECT_EQ
(
&
s
,
s
.
Find
Var
(
"a"
));
EXPECT_EQ
(
&
s
,
ss
.
Find
Var
(
"a"
));
EXPECT_EQ
(
&
s
,
s
.
Find
Scope
(
v
));
EXPECT_EQ
(
&
s
,
ss
.
Find
Scope
(
v
));
}
paddle/framework/variable.h
浏览文件 @
5031c93a
...
...
@@ -17,7 +17,6 @@
#include <typeinfo>
#include "paddle/platform/assert.h"
#include "paddle/string/piece.h"
namespace
paddle
{
namespace
framework
{
...
...
@@ -76,7 +75,7 @@ class Variable {
// the name; in the latter case, the variable should be identified
// by its address but not the unreadable name.
friend
class
Scope
;
string
::
Piece
name_
;
const
std
::
string
*
name_
;
};
}
// namespace framework
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录