Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a1a5adc9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a1a5adc9
编写于
12月 09, 2019
作者:
H
Huihuang Zheng
提交者:
GitHub
12月 09, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine English Doc of cond API (#21609)
As the title
上级
548efcd2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
10 deletion
+31
-10
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+31
-10
未找到文件。
python/paddle/fluid/layers/control_flow.py
浏览文件 @
a1a5adc9
...
...
@@ -1851,24 +1851,45 @@ def cond(pred, true_fn=None, false_fn=None, name=None):
list of tensors.
Note:
The tuples or lists in ``true_fn`` and ``false_fn`` must have same
shape because of dataflow model of PaddlePaddle while the tensors in the
tuples or the lists can have different shapes.
1. The tuples or lists returned by ``true_fn`` and ``false_fn`` must have
the same shape because of dataflow model of PaddlePaddle while the
tensors in the tuples or the lists can have different shapes.
2. Any tensors or operations created outside of ``true_fn`` and
``false_fn`` will be executed regardless of which branch is selected at
runtime. This has frequently surprised users who expected a lazy
semantics. For example:
.. code-block:: python
import paddle.fluid as fluid
a = fluid.data(name='a', shape=[-1, 1], dtype='float32')
b = fluid.data(name='b', shape=[-1, 1], dtype='float32')
c = a * b
out = fluid.layers.cond(a < b, lambda: a + c, lambda: b * b)
No matter whether ``a < b`` , ``c = a * b`` will run.
Args:
pred(Variable): A boolean tensor whose numel should be 1. The boolean
value determines whether to return the result of ``true_fn`` or
``false_fn``
true_fn(callable): A callable to be performed if ``pred`` is true
false_fn(callable): A callable to be performed if ``pred`` is false
name(str, optional): The default value is ``None``. Normally users
``false_fn`` .
true_fn(callable, optional): A callable to be performed if ``pred`` is
true. The default value is ``None`` .
false_fn(callable, optional): A callable to be performed if ``pred`` is
false. The default value is ``None`` .
name(str, optional): The default value is ``None`` . Normally users
don't have to set this parameter. For more information, please
refer to :ref:`api_guide_Name`.
refer to :ref:`api_guide_Name` .
Returns:
Variable|list(Variable)|tuple(Variable): returns ``true_fn()`` if the
predicate ``pred`` is true else ``false_fn()`` .
Raises:
TypeError: if ``true_fn`` or ``false_fn`` is not callable.
ValueError: if ``true_fn`` and ``false_fn`` do
esn't return the same
nest
structure of tensors.
ValueError: if ``true_fn`` and ``false_fn`` do
n't return the same nest
structure of tensors.
Examples:
.. code-block:: python
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录