Skip to content

Commit

Permalink
Merge pull request #11531 from reyoung/feature/non_layer_api_doc
Browse files Browse the repository at this point in the history
Polish Non-Layer API
  • Loading branch information
reyoung authored Jun 20, 2018
2 parents 8d5ab1f + d1203e3 commit b94f784
Show file tree
Hide file tree
Showing 8 changed files with 545 additions and 93 deletions.
3 changes: 2 additions & 1 deletion python/paddle/fluid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import transpiler
from param_attr import ParamAttr, WeightNormParamAttr
from data_feeder import DataFeeder
from core import LoDTensor, CPUPlace, CUDAPlace, CUDAPinnedPlace
from core import LoDTensor, CPUPlace, CUDAPlace, CUDAPinnedPlace, Scope
from transpiler import DistributeTranspiler, InferenceTranspiler, \
memory_optimize, release_memory
from concurrency import (Go, make_channel, channel_send, channel_recv,
Expand Down Expand Up @@ -83,6 +83,7 @@
'profiler',
'unique_name',
'recordio_writer',
'Scope',
]


Expand Down
20 changes: 20 additions & 0 deletions python/paddle/fluid/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@


def global_scope():
"""
Get the global/default scope instance. There are a lot of APIs use
:code:`global_scope` as its default value, e.g., :code:`Executor.run`
Returns:
Scope: The global/default scope instance.
"""
return g_scope


Expand All @@ -37,6 +44,19 @@ def switch_scope(scope):

@contextlib.contextmanager
def scope_guard(scope):
"""
Change the global/default scope instance by Python `with` statement. All
variable in runtime will assigned to the new scope.
Examples:
>>> import paddle.fluid as fluid
>>> new_scope = fluid.Scope()
>>> with fluid.scope_guard(new_scope):
>>> ...
Args:
scope: The new global/default scope.
"""
ex = switch_scope(scope)
yield
switch_scope(ex)
Expand Down
Loading

0 comments on commit b94f784

Please sign in to comment.