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

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

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