提交 c15f0925 编写于 作者: T Travis CI

Deploy to GitHub Pages: e593113a

上级 70e497e3
......@@ -243,7 +243,7 @@ class SymbolTable {
// TODO determine whether name is generated by python or C++.
// Currently assume that a unique name will be generated by C++ if the
// argument name is left default.
VarDesc* NewVar(const string& name="");
VarDesc* Var(const string& name="");
// find a VarDesc by name, if recursive is true, find parent's SymbolTable
// recursively.
......
......@@ -37,7 +37,7 @@ Scope is an association of a name to variable. All variables belong to `Scope`.
```cpp
class Scope {
public:
Variable* NewVar(const std::string& name);
Variable* Var(const std::string& name);
const Variable* FindVar(const std::string& name) const;
private:
......@@ -98,7 +98,7 @@ class Scope {
Variable* FindVar(const std::string& name) const;
// return if already contains same name variable.
Variable* NewVar(const std::string& name);
Variable* Var(const std::string& name);
private:
std::shared_ptr<Scope> parent_;
......@@ -107,7 +107,7 @@ class Scope {
```
## Only scope can create a variable
To ensure `only scope can create a variable`, we should mark `Variable`'s constructor as a private member function, and Scope is a friend class of Variable. And then only `NewVar` can construct `Variable`.
To ensure `only scope can create a variable`, we should mark `Variable`'s constructor as a private member function, and Scope is a friend class of Variable. And then only `Var` can construct `Variable`.
## When scope destroyed, all variables inside this scope should be destroyed together
......@@ -121,4 +121,4 @@ Also, as the parent scope is a `shared_ptr`, we can only `Create()` a scope shar
## Orthogonal interface
`FindVar` will return `nullptr` when `name` is not found. It can be used as `Contains` method. `NewVar` will return an `Error` when there is a name conflict locally. Combine `FindVar` and `NewVar`, we can implement `NewVar` easily.
`FindVar` will return `nullptr` when `name` is not found. It can be used as `Contains` method. `Var` will return an `Error` when there is a name conflict locally. Combine `FindVar` and `Var`, we can implement `Var` easily.
......@@ -161,7 +161,7 @@ class TensorArray:
@name: str
the name of the variable to output.
'''
tensor = NewVar(name)
tensor = Var(name)
tensor_array_stack(self.name, tensor)
return tensor
......
......@@ -397,7 +397,7 @@ Child block&#8217;s name scopes should inherit the parent&#8217;s so that OpDesc
<span class="c1">// TODO determine whether name is generated by python or C++.</span>
<span class="c1">// Currently assume that a unique name will be generated by C++ if the</span>
<span class="c1">// argument name is left default.</span>
<span class="n">VarDesc</span><span class="o">*</span> <span class="nf">NewVar</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">);</span>
<span class="n">VarDesc</span><span class="o">*</span> <span class="nf">Var</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">);</span>
<span class="c1">// find a VarDesc by name, if recursive is true, find parent&#39;s SymbolTable</span>
<span class="c1">// recursively.</span>
......
......@@ -213,7 +213,7 @@
</ol>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Scope</span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">Variable</span><span class="o">*</span> <span class="n">NewVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="n">Variable</span><span class="o">*</span> <span class="n">Var</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="k">const</span> <span class="n">Variable</span><span class="o">*</span> <span class="nf">FindVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="k">private</span><span class="o">:</span>
......@@ -272,7 +272,7 @@
<span class="n">Variable</span><span class="o">*</span> <span class="nf">FindVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="c1">// return if already contains same name variable.</span>
<span class="n">Variable</span><span class="o">*</span> <span class="nf">NewVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="n">Variable</span><span class="o">*</span> <span class="nf">Var</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="k">private</span><span class="o">:</span>
<span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">Scope</span><span class="o">&gt;</span> <span class="n">parent_</span><span class="p">;</span>
......@@ -282,7 +282,7 @@
</div>
<div class="section" id="only-scope-can-create-a-variable">
<span id="only-scope-can-create-a-variable"></span><h2>Only scope can create a variable<a class="headerlink" href="#only-scope-can-create-a-variable" title="Permalink to this headline"></a></h2>
<p>To ensure <code class="docutils literal"><span class="pre">only</span> <span class="pre">scope</span> <span class="pre">can</span> <span class="pre">create</span> <span class="pre">a</span> <span class="pre">variable</span></code>, we should mark <code class="docutils literal"><span class="pre">Variable</span></code>&#8216;s constructor as a private member function, and Scope is a friend class of Variable. And then only <code class="docutils literal"><span class="pre">NewVar</span></code> can construct <code class="docutils literal"><span class="pre">Variable</span></code>.</p>
<p>To ensure <code class="docutils literal"><span class="pre">only</span> <span class="pre">scope</span> <span class="pre">can</span> <span class="pre">create</span> <span class="pre">a</span> <span class="pre">variable</span></code>, we should mark <code class="docutils literal"><span class="pre">Variable</span></code>&#8216;s constructor as a private member function, and Scope is a friend class of Variable. And then only <code class="docutils literal"><span class="pre">Var</span></code> can construct <code class="docutils literal"><span class="pre">Variable</span></code>.</p>
</div>
<div class="section" id="when-scope-destroyed-all-variables-inside-this-scope-should-be-destroyed-together">
<span id="when-scope-destroyed-all-variables-inside-this-scope-should-be-destroyed-together"></span><h2>When scope destroyed, all variables inside this scope should be destroyed together<a class="headerlink" href="#when-scope-destroyed-all-variables-inside-this-scope-should-be-destroyed-together" title="Permalink to this headline"></a></h2>
......@@ -295,7 +295,7 @@
</div>
<div class="section" id="orthogonal-interface">
<span id="orthogonal-interface"></span><h2>Orthogonal interface<a class="headerlink" href="#orthogonal-interface" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">FindVar</span></code> will return <code class="docutils literal"><span class="pre">nullptr</span></code> when <code class="docutils literal"><span class="pre">name</span></code> is not found. It can be used as <code class="docutils literal"><span class="pre">Contains</span></code> method. <code class="docutils literal"><span class="pre">NewVar</span></code> will return an <code class="docutils literal"><span class="pre">Error</span></code> when there is a name conflict locally. Combine <code class="docutils literal"><span class="pre">FindVar</span></code> and <code class="docutils literal"><span class="pre">NewVar</span></code>, we can implement <code class="docutils literal"><span class="pre">NewVar</span></code> easily.</p>
<p><code class="docutils literal"><span class="pre">FindVar</span></code> will return <code class="docutils literal"><span class="pre">nullptr</span></code> when <code class="docutils literal"><span class="pre">name</span></code> is not found. It can be used as <code class="docutils literal"><span class="pre">Contains</span></code> method. <code class="docutils literal"><span class="pre">Var</span></code> will return an <code class="docutils literal"><span class="pre">Error</span></code> when there is a name conflict locally. Combine <code class="docutils literal"><span class="pre">FindVar</span></code> and <code class="docutils literal"><span class="pre">Var</span></code>, we can implement <code class="docutils literal"><span class="pre">Var</span></code> easily.</p>
</div>
</div>
......
......@@ -322,7 +322,7 @@ for example</p>
<span class="sd"> @name: str</span>
<span class="sd"> the name of the variable to output.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">tensor</span> <span class="o">=</span> <span class="n">NewVar</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="n">tensor</span> <span class="o">=</span> <span class="n">Var</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="n">tensor_array_stack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">tensor</span><span class="p">)</span>
<span class="k">return</span> <span class="n">tensor</span>
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -243,7 +243,7 @@ class SymbolTable {
// TODO determine whether name is generated by python or C++.
// Currently assume that a unique name will be generated by C++ if the
// argument name is left default.
VarDesc* NewVar(const string& name="");
VarDesc* Var(const string& name="");
// find a VarDesc by name, if recursive is true, find parent's SymbolTable
// recursively.
......
......@@ -37,7 +37,7 @@ Scope is an association of a name to variable. All variables belong to `Scope`.
```cpp
class Scope {
public:
Variable* NewVar(const std::string& name);
Variable* Var(const std::string& name);
const Variable* FindVar(const std::string& name) const;
private:
......@@ -98,7 +98,7 @@ class Scope {
Variable* FindVar(const std::string& name) const;
// return if already contains same name variable.
Variable* NewVar(const std::string& name);
Variable* Var(const std::string& name);
private:
std::shared_ptr<Scope> parent_;
......@@ -107,7 +107,7 @@ class Scope {
```
## Only scope can create a variable
To ensure `only scope can create a variable`, we should mark `Variable`'s constructor as a private member function, and Scope is a friend class of Variable. And then only `NewVar` can construct `Variable`.
To ensure `only scope can create a variable`, we should mark `Variable`'s constructor as a private member function, and Scope is a friend class of Variable. And then only `Var` can construct `Variable`.
## When scope destroyed, all variables inside this scope should be destroyed together
......@@ -121,4 +121,4 @@ Also, as the parent scope is a `shared_ptr`, we can only `Create()` a scope shar
## Orthogonal interface
`FindVar` will return `nullptr` when `name` is not found. It can be used as `Contains` method. `NewVar` will return an `Error` when there is a name conflict locally. Combine `FindVar` and `NewVar`, we can implement `NewVar` easily.
`FindVar` will return `nullptr` when `name` is not found. It can be used as `Contains` method. `Var` will return an `Error` when there is a name conflict locally. Combine `FindVar` and `Var`, we can implement `Var` easily.
......@@ -161,7 +161,7 @@ class TensorArray:
@name: str
the name of the variable to output.
'''
tensor = NewVar(name)
tensor = Var(name)
tensor_array_stack(self.name, tensor)
return tensor
......
......@@ -411,7 +411,7 @@ Child block&#8217;s name scopes should inherit the parent&#8217;s so that OpDesc
<span class="c1">// TODO determine whether name is generated by python or C++.</span>
<span class="c1">// Currently assume that a unique name will be generated by C++ if the</span>
<span class="c1">// argument name is left default.</span>
<span class="n">VarDesc</span><span class="o">*</span> <span class="nf">NewVar</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">);</span>
<span class="n">VarDesc</span><span class="o">*</span> <span class="nf">Var</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">);</span>
<span class="c1">// find a VarDesc by name, if recursive is true, find parent&#39;s SymbolTable</span>
<span class="c1">// recursively.</span>
......
......@@ -227,7 +227,7 @@
</ol>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Scope</span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">Variable</span><span class="o">*</span> <span class="n">NewVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="n">Variable</span><span class="o">*</span> <span class="n">Var</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="k">const</span> <span class="n">Variable</span><span class="o">*</span> <span class="nf">FindVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="k">private</span><span class="o">:</span>
......@@ -286,7 +286,7 @@
<span class="n">Variable</span><span class="o">*</span> <span class="nf">FindVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="c1">// return if already contains same name variable.</span>
<span class="n">Variable</span><span class="o">*</span> <span class="nf">NewVar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="n">Variable</span><span class="o">*</span> <span class="nf">Var</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">name</span><span class="p">);</span>
<span class="k">private</span><span class="o">:</span>
<span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">Scope</span><span class="o">&gt;</span> <span class="n">parent_</span><span class="p">;</span>
......@@ -296,7 +296,7 @@
</div>
<div class="section" id="only-scope-can-create-a-variable">
<span id="only-scope-can-create-a-variable"></span><h2>Only scope can create a variable<a class="headerlink" href="#only-scope-can-create-a-variable" title="永久链接至标题"></a></h2>
<p>To ensure <code class="docutils literal"><span class="pre">only</span> <span class="pre">scope</span> <span class="pre">can</span> <span class="pre">create</span> <span class="pre">a</span> <span class="pre">variable</span></code>, we should mark <code class="docutils literal"><span class="pre">Variable</span></code>&#8216;s constructor as a private member function, and Scope is a friend class of Variable. And then only <code class="docutils literal"><span class="pre">NewVar</span></code> can construct <code class="docutils literal"><span class="pre">Variable</span></code>.</p>
<p>To ensure <code class="docutils literal"><span class="pre">only</span> <span class="pre">scope</span> <span class="pre">can</span> <span class="pre">create</span> <span class="pre">a</span> <span class="pre">variable</span></code>, we should mark <code class="docutils literal"><span class="pre">Variable</span></code>&#8216;s constructor as a private member function, and Scope is a friend class of Variable. And then only <code class="docutils literal"><span class="pre">Var</span></code> can construct <code class="docutils literal"><span class="pre">Variable</span></code>.</p>
</div>
<div class="section" id="when-scope-destroyed-all-variables-inside-this-scope-should-be-destroyed-together">
<span id="when-scope-destroyed-all-variables-inside-this-scope-should-be-destroyed-together"></span><h2>When scope destroyed, all variables inside this scope should be destroyed together<a class="headerlink" href="#when-scope-destroyed-all-variables-inside-this-scope-should-be-destroyed-together" title="永久链接至标题"></a></h2>
......@@ -309,7 +309,7 @@
</div>
<div class="section" id="orthogonal-interface">
<span id="orthogonal-interface"></span><h2>Orthogonal interface<a class="headerlink" href="#orthogonal-interface" title="永久链接至标题"></a></h2>
<p><code class="docutils literal"><span class="pre">FindVar</span></code> will return <code class="docutils literal"><span class="pre">nullptr</span></code> when <code class="docutils literal"><span class="pre">name</span></code> is not found. It can be used as <code class="docutils literal"><span class="pre">Contains</span></code> method. <code class="docutils literal"><span class="pre">NewVar</span></code> will return an <code class="docutils literal"><span class="pre">Error</span></code> when there is a name conflict locally. Combine <code class="docutils literal"><span class="pre">FindVar</span></code> and <code class="docutils literal"><span class="pre">NewVar</span></code>, we can implement <code class="docutils literal"><span class="pre">NewVar</span></code> easily.</p>
<p><code class="docutils literal"><span class="pre">FindVar</span></code> will return <code class="docutils literal"><span class="pre">nullptr</span></code> when <code class="docutils literal"><span class="pre">name</span></code> is not found. It can be used as <code class="docutils literal"><span class="pre">Contains</span></code> method. <code class="docutils literal"><span class="pre">Var</span></code> will return an <code class="docutils literal"><span class="pre">Error</span></code> when there is a name conflict locally. Combine <code class="docutils literal"><span class="pre">FindVar</span></code> and <code class="docutils literal"><span class="pre">Var</span></code>, we can implement <code class="docutils literal"><span class="pre">Var</span></code> easily.</p>
</div>
</div>
......
......@@ -336,7 +336,7 @@ for example</p>
<span class="sd"> @name: str</span>
<span class="sd"> the name of the variable to output.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">tensor</span> <span class="o">=</span> <span class="n">NewVar</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="n">tensor</span> <span class="o">=</span> <span class="n">Var</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="n">tensor_array_stack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">tensor</span><span class="p">)</span>
<span class="k">return</span> <span class="n">tensor</span>
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册