[Dy2Stat] Refine code example for 2.0 (#28440)

TCChenlong-patch-1
Aurelius84 4 years ago committed by GitHub
parent f6834034cc
commit bd8dfe38ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -176,24 +176,20 @@ def declarative(function=None, input_spec=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np from paddle.jit import to_static
from paddle.fluid.dygraph.jit import declarative
fluid.enable_dygraph()
@declarative @to_static
def func(x): def func(x):
x = fluid.dygraph.to_variable(x) if paddle.mean(x) < 0:
if fluid.layers.mean(x) < 0:
x_v = x - 1 x_v = x - 1
else: else:
x_v = x + 1 x_v = x + 1
return x_v return x_v
x = np.ones([1, 2]) x = paddle.ones([1, 2], dtype='float32')
x_v = func(x) x_v = func(x)
print(x_v.numpy()) # [[2. 2.]] print(x_v) # [[2. 2.]]
""" """

Loading…
Cancel
Save