You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Paddle/doc/design/scope.md

31 lines
725 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Scope
### Define
Scope is a context to manage Variables. It mainly contains a map from Variable name to Variable. Net will get and update variable throw scope.
```cpp
class Scope {
Variable GetVar();
private:
// var_name -> var
std::map<string, Variable> var_map_;
Scope* parent_scope_;
}
```
You need to specify a scope to run a Net. One net can run in different scopes and update different variable in the scope. If you did not specify one, It will run in a default scope.
```python
with ScopeGuard(scope)
Net net = Net();
Net.run()
```
### Chain structure
Scope has a pointer point to it's parent scope, this is mainly used in RNN when it need to create many stepNet.
### Scope Guard