[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:
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
from paddle.fluid.dygraph.jit import declarative
fluid.enable_dygraph()
import paddle
from paddle.jit import to_static
@declarative
@to_static
def func(x):
x = fluid.dygraph.to_variable(x)
if fluid.layers.mean(x) < 0:
if paddle.mean(x) < 0:
x_v = x - 1
else:
x_v = x + 1
return x_v
x = np.ones([1, 2])
x = paddle.ones([1, 2], dtype='float32')
x_v = func(x)
print(x_v.numpy()) # [[2. 2.]]
print(x_v) # [[2. 2.]]
"""

Loading…
Cancel
Save