Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d0c111cf
提交
d0c111cf
authored
10月 20, 2011
作者:
Razvan Pascanu
提交者:
David Warde-Farley
11月 16, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added more documentation
Specifically I insisted on the fact that the ifelse can deal with multiple tensors on the then/else branches.
上级
55bde57e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
24 行删除
+43
-24
ifelse.py
theano/ifelse.py
+43
-24
没有找到文件。
theano/ifelse.py
浏览文件 @
d0c111cf
"""
IfElse is an Op that works with the LazyLinker to support conditional graph
evaluation.
:TODO: Add text to library documentation describing the IfElse Op.
IfElse introduces lazy evaluation in Theano (coupled with the CVM/VM
linkers). It resembles the if clause of any programming languages, that
has a `then` and `else` branch, and executes either one or the other
according to the condition provided.
This op contrast the already existent `swtich` op, that will evaluate both
branches of the clause and afterwards pick (according to the condition)
which value to report. Note also that `switch` is an elemwise operations (so
it picks each entry of a matrix according to the condition) while `ifelse`
is a global operation with a scalar condition.
"""
__docformat__
=
'restructedtext en'
...
...
@@ -30,14 +36,23 @@ _logger = logging.getLogger('theano.ifelse')
class
IfElse
(
PureOp
):
"""
Op that works with CVM/VM to support conditional graph evaluation. Note,
this op is not suppose to be used directly, it should be used through
the `ifelse` function. The op supports mutile values that are all
conditioned by the same 'tf'.
Op that provides conditional graph evaluation if used with the CVM/VM
linkers. Note that there exist a helpful function `ifelse` that should
be used to instantiate the op!
According to a scalar condition `condition` the op evaluates and then
returns all the tensors provided on the `then` branch, otherwise it
evaluates and returns the tensors provided on the `else` branch. The op
supports multiple tensors on each branch, conditioned that the same
number of tensors are on the `then` as on the `else` and there is a one
to one correspondance between them (shape and dtype wise).
The `then` branch is defined as the first N tensors (after the
condition), while the `else` branch is defined as the last N tensors.
Example usage:
``rval = ifelse(
tf
, rval_if_true1, rval_if_true2, .., rval_if_trueN,
``rval = ifelse(
condition
, rval_if_true1, rval_if_true2, .., rval_if_trueN,
rval_if_false1, rval_if_false2, .., rval_if_falseN)``
:note:
...
...
@@ -243,34 +258,38 @@ class IfElse(PureOp):
return
thunk
def
ifelse
(
cond
,
true_branch
,
false_branch
,
name
=
None
):
def
ifelse
(
cond
ition
,
true_branch
,
false_branch
,
name
=
None
):
"""
This function corresponds to a
if statement, returning inputs in the
``true_branch`` if ``cond`` evaluates to True or inputs in the
``false_branch`` if ``cond
`` evalutates to False.
This function corresponds to a
n if statement, returning (and evaluating)
inputs in the ``true_branch`` if ``condition`` evaluates to True or
inputs in the ``false_branch`` if ``condition
`` evalutates to False.
:param cond:
``cond`` should be a tensor scalar representing the condition. If it
evaluates to 0 it corresponds to False, anything else stands for
True.
:type condition: scalar like
:param condition:
``condition`` should be a tensor scalar representing the condition.
If it evaluates to 0 it corresponds to False, anything else stands
for True.
:type true_branch: list of theano expressions/ theano expressions
:param true_branch:
A single theano variable or a list of theano variables that the
function should return as the output if ``cond`` evaluates to true.
function should return as the output if ``cond
ition
`` evaluates to true.
The number of variables should match those in the false_branch, and
the
types (of each) should also correspond to those in the fals
e
branch.
the
re should be a one to one correspondance (type wise) with th
e
tensors provided in the false branch
:type false_branch: list of theano expressions/ theano expressions
:param false_branch:
A single theano variable or a list of theano variables that the
function should return as the output if ``cond`` evaluates to false.
function should return as the output if ``cond
ition
`` evaluates to false.
The number of variables should match those in the true branch, and
the types (of each) should also match those in the true branch.
there should be a one to one correspondace (type wise) with the
tensors provided in the true branch.
:return:
A list of theano variables or a single variable (
depending on the
A list of theano variables or a single variable (depending on the
nature of the ``true_branch`` and ``false_branch``). More exactly if
``true_branch`` and ``false_branch``
contain a single element
, then
``true_branch`` and ``false_branch``
is a tensor
, then
the return variable will be just a single variable, otherwise a
list. The value returns correspond either to the values in the
``true_branch`` or in the ``false_branch`` depending on the value of
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论