未验证 提交 0ce933a9 编写于 作者: L liym27 提交者: GitHub

[API2.0] Fix documents of 6 APIs to fit API2.0: (#28514)

1. Remove 'fluid';
2. Variable -> Tensor

APIs:
 sum, convert_call, convert_ifelse,
 convert_logical_and, convert_logical_or, convert_logical_not
上级 3b0d31ab
...@@ -98,25 +98,27 @@ def convert_call(func): ...@@ -98,25 +98,27 @@ def convert_call(func):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
from paddle.fluid.dygraph.dygraph_to_static import convert_call from paddle.jit.dy2static import convert_call
def dyfunc(x): paddle.enable_static()
if fluid.layers.mean(x) < 0: def dyfunc(x):
x_v = x - 1 if paddle.mean(x) < 0:
else: x_v = x - 1
x_v = x + 1 else:
x_v = x + 1
return x_v return x_v
new_func = convert_call(dyfunc)
x = fluid.layers.fill_constant(shape=[3, 3], value=0, dtype='float64') new_func = convert_call(dyfunc)
x_v = new_func(x) x = paddle.tensor.manipulation.fill_constant(shape=[3, 3], value=0, dtype='float64')
exe = fluid.Executor(fluid.CPUPlace()) x_v = new_func(x)
out = exe.run(fetch_list=[x_v])
print(out[0]) exe = paddle.static.Executor(paddle.CPUPlace())
# [[1. 1. 1.] out = exe.run(fetch_list=[x_v])
# [1. 1. 1.] print(out[0])
# [1. 1. 1.]] # [[1. 1. 1.]
# [1. 1. 1.]
# [1. 1. 1.]]
""" """
translator_logger.log(1, translator_logger.log(1,
......
...@@ -24,7 +24,7 @@ def convert_while_loop(cond, body, loop_vars): ...@@ -24,7 +24,7 @@ def convert_while_loop(cond, body, loop_vars):
A function representation of a Python ``while`` statement. A function representation of a Python ``while`` statement.
Args: Args:
cond(Callable): A callable object that returns a boolean variable to control whether to execute the loop body. It takes ``loop_vars`` as arguments. cond(Callable): A callable object that returns a boolean variable to control whether to execute the loop body. It takes ``loop_vars`` as arguments.
body(Callable): A callable object that returns a tuple or list of variables with the same arguments ``loops_vars`` as ``cond`` . body(Callable): A callable object that returns a tuple or list of variables with the same arguments ``loops_vars`` as ``cond`` .
loop_vars(list|tuple): A list or tuple of variables passed to ``cond`` and ``body`` . loop_vars(list|tuple): A list or tuple of variables passed to ``cond`` and ``body`` .
...@@ -44,7 +44,7 @@ def convert_while_loop(cond, body, loop_vars): ...@@ -44,7 +44,7 @@ def convert_while_loop(cond, body, loop_vars):
def _run_paddle_while_loop(cond, body, loop_vars): def _run_paddle_while_loop(cond, body, loop_vars):
# NOTE: loop_vars of Paddle op `control_flow.while_loop` must be Paddle Variable. # NOTE: loop_vars of Paddle op `control_flow.while_loop` must be Paddle Tensors.
loop_vars = [to_static_variable(var) for var in loop_vars] loop_vars = [to_static_variable(var) for var in loop_vars]
loop_vars = control_flow.while_loop(cond, body, loop_vars) loop_vars = control_flow.while_loop(cond, body, loop_vars)
return loop_vars return loop_vars
...@@ -61,8 +61,8 @@ def convert_logical_and(x, y): ...@@ -61,8 +61,8 @@ def convert_logical_and(x, y):
A function representation of a Python ``and`` statement. A function representation of a Python ``and`` statement.
Args: Args:
x(bool|Variable): Left hand operand of ``and`` operator. x(bool|Tensor): Left hand operand of ``and`` operator.
y(bool|Variable): Right hand operand of ``and`` operator. y(bool|Tensor): Right hand operand of ``and`` operator.
Returns: Returns:
A python bool variable or a bool Tensor. A python bool variable or a bool Tensor.
...@@ -94,8 +94,8 @@ def convert_logical_or(x, y): ...@@ -94,8 +94,8 @@ def convert_logical_or(x, y):
A function representation of a Python ``or`` statement. A function representation of a Python ``or`` statement.
Args: Args:
x(bool|Variable): Left hand operand of ``or`` operator. x(bool|Tensor): Left hand operand of ``or`` operator.
y(bool|Variable): Right hand operand of ``or`` operator. y(bool|Tensor): Right hand operand of ``or`` operator.
Returns: Returns:
A python bool variable or a bool Tensor. A python bool variable or a bool Tensor.
...@@ -127,7 +127,7 @@ def convert_logical_not(x): ...@@ -127,7 +127,7 @@ def convert_logical_not(x):
A function representation of a Python ``not`` statement. A function representation of a Python ``not`` statement.
Args: Args:
x(bool|Variable): Operand of of ``not`` operator. x(bool|Tensor): Operand of of ``not`` operator.
Returns: Returns:
A python bool variable or a bool Tensor. A python bool variable or a bool Tensor.
...@@ -153,7 +153,7 @@ def convert_ifelse(pred, true_fn, false_fn, true_args, false_args, return_vars): ...@@ -153,7 +153,7 @@ def convert_ifelse(pred, true_fn, false_fn, true_args, false_args, return_vars):
A function representation of a Python ``if/else`` statement. A function representation of a Python ``if/else`` statement.
Args: Args:
pred(bool|Variable): A boolean variable which determines whether to return the result of ``true_fn`` or ``false_fn`` . pred(bool|Tensor): A boolean Tensor which determines whether to return the result of ``true_fn`` or ``false_fn`` .
true_fn(callable): A callable to be performed if ``pred`` is true. true_fn(callable): A callable to be performed if ``pred`` is true.
false_fn(callable): A callable to be performed if ``pred`` is false. false_fn(callable): A callable to be performed if ``pred`` is false.
true_args(tuple): Parameters of ``true_fn``. true_args(tuple): Parameters of ``true_fn``.
...@@ -175,7 +175,7 @@ def _run_paddle_cond(pred, true_fn, false_fn, true_args, false_args, ...@@ -175,7 +175,7 @@ def _run_paddle_cond(pred, true_fn, false_fn, true_args, false_args,
return_vars): return_vars):
return_var_ids = [id(var) for var in return_vars] return_var_ids = [id(var) for var in return_vars]
# NOTE 1: return vars of Paddle op `control_flow.cond` must be Paddle Variable # NOTE 1: Returned vars of Paddle op `control_flow.cond` must be Paddle Tensors
# NOTE 2: Here uses id(var) not var, because `if var in return_var` use operator `==`, # NOTE 2: Here uses id(var) not var, because `if var in return_var` use operator `==`,
# which will call `fluid.layers.equal` and causes error when var in return_vars is not initialized. # which will call `fluid.layers.equal` and causes error when var in return_vars is not initialized.
true_args = [ true_args = [
......
...@@ -627,7 +627,6 @@ def sum(x, axis=None, dtype=None, keepdim=False, name=None): ...@@ -627,7 +627,6 @@ def sum(x, axis=None, dtype=None, keepdim=False, name=None):
.. code-block:: python .. code-block:: python
import paddle import paddle
paddle.disable_static()
# x is a Tensor with following elements: # x is a Tensor with following elements:
# [[0.2, 0.3, 0.5, 0.9] # [[0.2, 0.3, 0.5, 0.9]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册