提交 7a485077 编写于 作者: Q qiaolongfei

fix code style

上级 674b1d34
...@@ -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& getVar(const std::string& name) const; const VariablePtr& GetVar(const std::string& name) const;
//! Create or get a variable in this scope. //! Create or get a variable in this scope.
VariablePtr& createOrGetVar(const std::string& name); VariablePtr& GetOrCreateVar(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 = newVar("X"); // x is created in scope global, implicitly. auto x = NewVar("X"); // x is created in scope global, implicitly.
auto y = newVar("Y"); auto y = NewVar("Y");
Net net1; Net net1;
net1.addOp("add", {x, y}, {x}); // x = x + y; net1.AddOp("add", {x, y}, {x}); // x = x + y;
net1.run(); net1.Run();
for (size_t i=0; i<10; ++i) { for (size_t i=0; i<10; ++i) {
Scope local; Scope local;
auto tmp = newVar("tmp"); // tmp is created in scope local. auto tmp = NewVar("tmp"); // tmp is created in scope local.
Net net2; Net net2;
net2.addOp("add", {x, y}, {tmp}); net2.AddOp("add", {x, y}, {tmp});
net2.run(); // tmp = x + y; net2.Run(); // tmp = x + y;
} }
Net net3; Net net3;
net3.addOp("add", {x, y}, {"tmp"}); // error! cannot found "tmp" in global scope. net3.AddOp("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.
先完成此消息的编辑!
想要评论请 注册