From e7faae01300ef38ad78c270567384b36709a7c9e Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Thu, 21 Jun 2018 12:25:46 +0800 Subject: [PATCH] Refine assign layer Give assign layer's second parameter 'output' a default value: None. If it is None, the output variable will be created inside the layer. --- python/paddle/fluid/layers/tensor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index 149e77b5241..5adbde27be0 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -155,7 +155,7 @@ def cast(x, dtype): Examples: .. code-block:: python - + data = fluid.layers.data(name='x', shape=[13], dtype='float32') result = fluid.layers.cast(x=data, dtype='float64') """ @@ -188,7 +188,7 @@ def concat(input, axis=0, name=None): Examples: .. code-block:: python - + out = fluid.layers.concat(input=[Efirst, Esecond, Ethird, Efourth]) """ helper = LayerHelper('concat', **locals()) @@ -234,7 +234,7 @@ def sums(input, out=None): return out -def assign(input, output): +def assign(input, output=None): """ **Assign** @@ -242,7 +242,7 @@ def assign(input, output): Args: input(Variable|numpy.ndarray): The source variable - output(Variable): The destination variable + output(Variable|None): The destination variable Returns: Variable: The destination variable that was supplied as the *output*. @@ -255,6 +255,8 @@ def assign(input, output): fluid.layers.assign(hidden, out) """ helper = LayerHelper('assign', **locals()) + if output is None: + output = helper.create_tmp_variable(dtype=input.dtype) if isinstance(input, Variable): helper.append_op( type='assign', inputs={'X': [input]}, outputs={'Out': [output]}) -- GitLab