Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d9671761
提交
d9671761
authored
4月 08, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2720 from yingzha/ccw
added documentation and fixed the gradient of the Assert Op
上级
e7f13079
efd5c612
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
5 行删除
+33
-5
opt.py
theano/tensor/opt.py
+17
-5
test_assert_op_gradient.py
theano/tensor/tests/test_assert_op_gradient.py
+16
-0
没有找到文件。
theano/tensor/opt.py
浏览文件 @
d9671761
...
@@ -24,6 +24,7 @@ from theano.gof import opt, InconsistencyError, TopoOptimizer, graph
...
@@ -24,6 +24,7 @@ from theano.gof import opt, InconsistencyError, TopoOptimizer, graph
from
theano.gof
import
Variable
,
Constant
from
theano.gof
import
Variable
,
Constant
from
theano.compat.python2x
import
maxsize
from
theano.compat.python2x
import
maxsize
from
theano.gof.utils
import
MethodNotDefined
from
theano.gof.utils
import
MethodNotDefined
from
theano.gradient
import
DisconnectedType
from
theano.configparser
import
config
from
theano.configparser
import
config
from
theano.tensor.elemwise
import
Elemwise
,
DimShuffle
from
theano.tensor.elemwise
import
Elemwise
,
DimShuffle
from
theano.tensor.subtensor
import
(
get_idx_list
,
get_canonical_form_slice
,
from
theano.tensor.subtensor
import
(
get_idx_list
,
get_canonical_form_slice
,
...
@@ -1492,11 +1493,22 @@ class Assert(T.Op):
...
@@ -1492,11 +1493,22 @@ class Assert(T.Op):
"""
"""
Implements assertion in a computational graph.
Implements assertion in a computational graph.
Returns the first parameter if the condition is true, otherwise, triggers
AssertionError.
Example:
T = theano.tensor
x = T.vector('x')
assert_op = T.opt.Assert()
func = theano.function([x], assert_op(x, x.size<2))
Notes:
Notes:
This Op can be removed from the graph because of optimizations, and can
This Op is a debugging feature. It can be removed from the graph
hide some possible optimizations to the optimizer.
because of optimizations, and can hide some possible optimizations to
Also, the output of the Op must be returned by the function computing the
the optimizer. Specifically, removing happens if it can be determined
graph, otherwise it will not be used.
that condition will always be true. Also, the output of the Op must be
used in the function computing the graph, but it doesn't have to be
returned.
"""
"""
view_map
=
{
0
:
[
0
]}
view_map
=
{
0
:
[
0
]}
...
@@ -1533,7 +1545,7 @@ class Assert(T.Op):
...
@@ -1533,7 +1545,7 @@ class Assert(T.Op):
return
hash
(
type
(
self
))
^
hash
(
self
.
msg
)
return
hash
(
type
(
self
))
^
hash
(
self
.
msg
)
def
grad
(
self
,
input
,
output_gradients
):
def
grad
(
self
,
input
,
output_gradients
):
return
output_gradients
return
output_gradients
+
[
DisconnectedType
()()]
*
(
len
(
input
)
-
1
)
def
c_code
(
self
,
node
,
name
,
inames
,
onames
,
sub
):
def
c_code
(
self
,
node
,
name
,
inames
,
onames
,
sub
):
value
=
inames
[
0
]
value
=
inames
[
0
]
...
...
theano/tensor/tests/test_assert_op_gradient.py
0 → 100644
浏览文件 @
d9671761
import
numpy
import
theano
import
theano.tensor
as
T
from
theano.tensor.opt
import
Assert
def
test_assert_op_gradient
():
x
=
T
.
vector
(
'x'
)
assert_op
=
Assert
()
cost
=
T
.
sum
(
assert_op
(
x
,
x
.
size
<
2
))
grad
=
T
.
grad
(
cost
,
x
)
func
=
theano
.
function
([
x
],
grad
)
x_val
=
numpy
.
ones
(
shape
=
(
1
,))
assert
func
(
x_val
)
==
1
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论