Skip to content

Commit f0cf70e

Browse files
authored
Merge pull request #11646 from panyx0718/fix
Small doc fix and clean up of reshape
2 parents 2bc812d + ed4aa21 commit f0cf70e

File tree

1 file changed

+13
-6
lines changed
  • python/paddle/fluid/layers

1 file changed

+13
-6
lines changed

python/paddle/fluid/layers/nn.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,14 +4266,18 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
42664266
say :attr:`actual_shape` has a higher priority
42674267
than :attr:`shape`.
42684268
act (str): The non-linear activation to be applied to output variable.
4269-
inplace(bool): If this flag is set true, a new output tensor is created
4270-
whose data is copied from input x, otherwise the output
4271-
shares data with input without copying.
4269+
inplace(bool): If this flag is set true, the output
4270+
shares data with input without copying, otherwise
4271+
a new output tensor is created
4272+
whose data is copied from input x.
42724273
name (str): The name of this layer. It is optional.
42734274
42744275
Returns:
42754276
Variable: The output tensor.
42764277
4278+
Raises:
4279+
TypeError: if actual_shape is neither Variable nor None.
4280+
42774281
Examples:
42784282
.. code-block:: python
42794283
@@ -4285,6 +4289,11 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
42854289

42864290
if not (isinstance(shape, list) or isinstance(shape, tuple)):
42874291
raise ValueError("Input shape must be a python lsit or tuple.")
4292+
inputs = {"X": x}
4293+
if isinstance(actual_shape, Variable):
4294+
inputs["Shape"] = actual_shape
4295+
elif actual_shape is not None:
4296+
raise TypeError("actual_shape should either be Variable or None")
42884297

42894298
# Validate the shape
42904299
unk_dim_idx = -1
@@ -4305,9 +4314,7 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
43054314
reshaped = helper.create_tmp_variable(dtype=x.dtype)
43064315
helper.append_op(
43074316
type="reshape",
4308-
inputs={"X": x,
4309-
"Shape": actual_shape}
4310-
if isinstance(actual_shape, Variable) else {"X": x},
4317+
inputs=inputs,
43114318
attrs={"shape": shape,
43124319
"inplace": inplace},
43134320
outputs={"Out": reshaped})

0 commit comments

Comments
 (0)