Skip to content

Commit ed4aa21

Browse files
committed
Small doc fix and clean up of reshape
1 parent c90e64e commit ed4aa21

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
@@ -4263,14 +4263,18 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
42634263
say :attr:`actual_shape` has a higher priority
42644264
than :attr:`shape`.
42654265
act (str): The non-linear activation to be applied to output variable.
4266-
inplace(bool): If this flag is set true, a new output tensor is created
4267-
whose data is copied from input x, otherwise the output
4268-
shares data with input without copying.
4266+
inplace(bool): If this flag is set true, the output
4267+
shares data with input without copying, otherwise
4268+
a new output tensor is created
4269+
whose data is copied from input x.
42694270
name (str): The name of this layer. It is optional.
42704271
42714272
Returns:
42724273
Variable: The output tensor.
42734274
4275+
Raises:
4276+
TypeError: if actual_shape is neither Variable nor None.
4277+
42744278
Examples:
42754279
.. code-block:: python
42764280
@@ -4282,6 +4286,11 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
42824286

42834287
if not (isinstance(shape, list) or isinstance(shape, tuple)):
42844288
raise ValueError("Input shape must be a python lsit or tuple.")
4289+
inputs = {"X": x}
4290+
if isinstance(actual_shape, Variable):
4291+
inputs["Shape"] = actual_shape
4292+
elif actual_shape is not None:
4293+
raise TypeError("actual_shape should either be Variable or None")
42854294

42864295
# Validate the shape
42874296
unk_dim_idx = -1
@@ -4302,9 +4311,7 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
43024311
reshaped = helper.create_tmp_variable(dtype=x.dtype)
43034312
helper.append_op(
43044313
type="reshape",
4305-
inputs={"X": x,
4306-
"Shape": actual_shape}
4307-
if isinstance(actual_shape, Variable) else {"X": x},
4314+
inputs=inputs,
43084315
attrs={"shape": shape,
43094316
"inplace": inplace},
43104317
outputs={"Out": reshaped})

0 commit comments

Comments
 (0)