From fbdf77917e56a9604983846e322bb2bac501b0a8 Mon Sep 17 00:00:00 2001 From: liym27 <33742067+liym27@users.noreply.github.com> Date: Sat, 11 Apr 2020 22:32:03 +0800 Subject: [PATCH] fix example code of api data/switch_case to keep cn-doc and en-doc consistent (#23670) --- python/paddle/fluid/data.py | 14 +++++++------- python/paddle/fluid/layers/control_flow.py | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/python/paddle/fluid/data.py b/python/paddle/fluid/data.py index e0888c2c07..28923bfb27 100644 --- a/python/paddle/fluid/data.py +++ b/python/paddle/fluid/data.py @@ -40,7 +40,7 @@ def data(name, shape, dtype='float32', lod_level=0): `paddle.fluid.data` checks the shape and the dtype of data fed by Executor or ParallelExecutor during run time. - To feed variable size inputs, users can set -1 on the variable + To feed variable size inputs, users can set None or -1 on the variable dimension when using :code:`paddle.fluid.data`, or feed variable size inputs directly to :code:`paddle.fluid.layers.data` and PaddlePaddle will fit the size accordingly. @@ -54,14 +54,14 @@ def data(name, shape, dtype='float32', lod_level=0): name (str): The name/alias of the variable, see :ref:`api_guide_Name` for more details. shape (list|tuple): List|Tuple of integers declaring the shape. You can - set "None" at a dimension to indicate the dimension can be of any - size. For example, it is useful to set changeable batch size as "None" + set "None" or -1 at a dimension to indicate the dimension can be of any + size. For example, it is useful to set changeable batch size as "None" or -1. dtype (np.dtype|VarType|str, optional): The type of the data. Supported dtype: bool, float16, float32, float64, int8, int16, int32, int64, - uint8. Default: float32 + uint8. Default: float32. lod_level (int, optional): The LoD level of the LoDTensor. Usually users don't have to set this value. For more details about when and how to - use LoD level, see :ref:`user_guide_lod_tensor` . Default: 0 + use LoD level, see :ref:`user_guide_lod_tensor` . Default: 0. Returns: Variable: The global variable that gives access to the data. @@ -76,10 +76,10 @@ def data(name, shape, dtype='float32', lod_level=0): # User can only feed data of the same shape to x x = fluid.data(name='x', shape=[3, 2, 1], dtype='float32') - # Creates a variable with changeable batch size. + # Creates a variable with changeable batch size -1. # Users can feed data of any batch size into y, # but size of each data sample has to be [2, 1] - y = fluid.data(name='y', shape=[None, 2, 1], dtype='float32') + y = fluid.data(name='y', shape=[-1, 2, 1], dtype='float32') z = x + y diff --git a/python/paddle/fluid/layers/control_flow.py b/python/paddle/fluid/layers/control_flow.py index 67e5a3ebb8..dd94171e07 100755 --- a/python/paddle/fluid/layers/control_flow.py +++ b/python/paddle/fluid/layers/control_flow.py @@ -2332,7 +2332,7 @@ class Switch(object): Case and default functions can only be used inside the scope of Switch, as shown below: .. code-block:: python - + ''' with fluid.layers.Switch() as switch: with switch.case(cond1): @@ -3372,8 +3372,7 @@ def switch_case(branch_index, branch_fns, default=None, name=None): branch_fns=[(0, fn_1), (4, fn_2), (7, fn_3)]) exe = fluid.Executor(fluid.CPUPlace()) - res_1, res_2, res_3 = exe.run(main_program, - fetch_list=[out_1, out_2, out_3]) + res_1, res_2, res_3 = exe.run(main_program, fetch_list=[out_1, out_2, out_3]) print(res_1) # [[1. 1.]] print(res_2) # [[2 2] [2 2]] print(res_3) # [3 3 3] -- GitLab