Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7a485077
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
7a485077
编写于
6月 21, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code style
上级
674b1d34
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
11 addition
and
11 deletion
+11
-11
doc/design/scope.md
doc/design/scope.md
+11
-11
未找到文件。
doc/design/scope.md
浏览文件 @
7a485077
...
@@ -9,16 +9,16 @@ class Variable;
...
@@ -9,16 +9,16 @@ class Variable;
using
VariablePtr
=
std
::
shared_ptr
<
Variable
>
;
using
VariablePtr
=
std
::
shared_ptr
<
Variable
>
;
class
Scope
final
{
class
Scope
final
{
public:
public:
Scope
();
Scope
();
Scope
(
const
std
::
shared_ptr
<
Scope
>&
parent
);
Scope
(
const
std
::
shared_ptr
<
Scope
>&
parent
);
//! Get Variable in this scope.
//! Get Variable in this scope.
//! @return nullptr if no such variable.
//! @return nullptr if no such variable.
const
VariablePtr
&
g
etVar
(
const
std
::
string
&
name
)
const
;
const
VariablePtr
&
G
etVar
(
const
std
::
string
&
name
)
const
;
//! Create or get a variable in this scope.
//! Create or get a variable in this scope.
VariablePtr
&
createOrGet
Var
(
const
std
::
string
&
name
);
VariablePtr
&
GetOrCreate
Var
(
const
std
::
string
&
name
);
private:
private:
/// variable name -> variable
/// variable name -> variable
...
@@ -31,22 +31,22 @@ You need to specify a scope to run a Net. One net can run in different scopes an
...
@@ -31,22 +31,22 @@ You need to specify a scope to run a Net. One net can run in different scopes an
```
cpp
```
cpp
Scope
global
;
Scope
global
;
auto
x
=
n
ewVar
(
"X"
);
// x is created in scope global, implicitly.
auto
x
=
N
ewVar
(
"X"
);
// x is created in scope global, implicitly.
auto
y
=
n
ewVar
(
"Y"
);
auto
y
=
N
ewVar
(
"Y"
);
Net
net1
;
Net
net1
;
net1
.
a
ddOp
(
"add"
,
{
x
,
y
},
{
x
});
// x = x + y;
net1
.
A
ddOp
(
"add"
,
{
x
,
y
},
{
x
});
// x = x + y;
net1
.
r
un
();
net1
.
R
un
();
for
(
size_t
i
=
0
;
i
<
10
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
10
;
++
i
)
{
Scope
local
;
Scope
local
;
auto
tmp
=
n
ewVar
(
"tmp"
);
// tmp is created in scope local.
auto
tmp
=
N
ewVar
(
"tmp"
);
// tmp is created in scope local.
Net
net2
;
Net
net2
;
net2
.
a
ddOp
(
"add"
,
{
x
,
y
},
{
tmp
});
net2
.
A
ddOp
(
"add"
,
{
x
,
y
},
{
tmp
});
net2
.
r
un
();
// tmp = x + y;
net2
.
R
un
();
// tmp = x + y;
}
}
Net
net3
;
Net
net3
;
net3
.
a
ddOp
(
"add"
,
{
x
,
y
},
{
"tmp"
});
// error! cannot found "tmp" in global scope.
net3
.
A
ddOp
(
"add"
,
{
x
,
y
},
{
"tmp"
});
// error! cannot found "tmp" in global scope.
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录