未验证 提交 bd8dfe38 编写于 作者: A Aurelius84 提交者: GitHub

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

上级 f6834034
...@@ -176,24 +176,20 @@ def declarative(function=None, input_spec=None): ...@@ -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
@to_static
fluid.enable_dygraph() def func(x):
if paddle.mean(x) < 0:
@declarative x_v = x - 1
def func(x): else:
x = fluid.dygraph.to_variable(x) x_v = x + 1
if fluid.layers.mean(x) < 0: return x_v
x_v = x - 1
else: x = paddle.ones([1, 2], dtype='float32')
x_v = x + 1 x_v = func(x)
return x_v print(x_v) # [[2. 2.]]
x = np.ones([1, 2])
x_v = func(x)
print(x_v.numpy()) # [[2. 2.]]
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册