From beec87b911bafcd6e51c3c000df12bc0f130364f Mon Sep 17 00:00:00 2001 From: liym27 <33742067+liym27@users.noreply.github.com> Date: Mon, 2 Dec 2019 20:26:23 +0800 Subject: [PATCH] fix bug in example codes of API case and switch_case. test=develop,test=document_fix (#21477) --- python/paddle/fluid/layers/control_flow.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/layers/control_flow.py b/python/paddle/fluid/layers/control_flow.py index 4241d570644..4d42877ad4f 100755 --- a/python/paddle/fluid/layers/control_flow.py +++ b/python/paddle/fluid/layers/control_flow.py @@ -1911,6 +1911,7 @@ def case(pred_fn_pairs, default=None, name=None): .. code-block:: python import paddle.fluid as fluid + import paddle.fluid.layers as layers def fn_1(): return layers.fill_constant(shape=[1, 2], dtype='float32', value=1) @@ -1923,7 +1924,7 @@ def case(pred_fn_pairs, default=None, name=None): main_program = fluid.default_startup_program() startup_program = fluid.default_main_program() - with program_guard(main_program, startup_program): + with fluid.program_guard(main_program, startup_program): x = layers.fill_constant(shape=[1], dtype='float32', value=0.3) y = layers.fill_constant(shape=[1], dtype='float32', value=0.1) z = layers.fill_constant(shape=[1], dtype='float32', value=0.2) @@ -3014,6 +3015,8 @@ def switch_case(branch_index, branch_fns, default=None, name=None): .. code-block:: python import paddle.fluid as fluid + import paddle.fluid.layers as layers + def fn_1(): return layers.fill_constant(shape=[1, 2], dtype='float32', value=1) @@ -3025,7 +3028,7 @@ def switch_case(branch_index, branch_fns, default=None, name=None): main_program = fluid.default_startup_program() startup_program = fluid.default_main_program() - with program_guard(main_program, startup_program): + with fluid.program_guard(main_program, startup_program): index_1 = layers.fill_constant(shape=[1], dtype='int32', value=1) index_2 = layers.fill_constant(shape=[1], dtype='int32', value=2) -- GitLab