Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ad4c3a84
提交
ad4c3a84
authored
11月 13, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add optional opt local_remove_all_assert.
上级
a4b15802
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
6 行删除
+39
-6
opt.py
theano/tensor/opt.py
+17
-0
test_opt.py
theano/tensor/tests/test_opt.py
+22
-6
没有找到文件。
theano/tensor/opt.py
浏览文件 @
ad4c3a84
...
@@ -1582,6 +1582,23 @@ def local_remove_useless_assert(node):
...
@@ -1582,6 +1582,23 @@ def local_remove_useless_assert(node):
return
[
assert_
(
node
.
inputs
[
0
],
*
cond
)]
return
[
assert_
(
node
.
inputs
[
0
],
*
cond
)]
@gof.local_optimizer
([
Assert
])
def
local_remove_all_assert
(
node
):
"""An optimization disable by default that remove all assert from
the graph.
:note: See the :ref:`unsafe` section to know how to enable it.
"""
if
not
isinstance
(
node
.
op
,
Assert
):
return
return
[
node
.
inputs
[
0
]]
# Disabled by default
compile
.
optdb
[
'canonicalize'
]
.
register
(
'local_remove_all_assert'
,
local_remove_all_assert
)
@register_specialize
@register_specialize
@gof.local_optimizer
([
T
.
Elemwise
])
@gof.local_optimizer
([
T
.
Elemwise
])
def
local_elemwise_alloc
(
node
):
def
local_elemwise_alloc
(
node
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
ad4c3a84
...
@@ -3224,8 +3224,8 @@ class test_assert(utt.InferShapeTester):
...
@@ -3224,8 +3224,8 @@ class test_assert(utt.InferShapeTester):
f
(
1
,
1
)
f
(
1
,
1
)
self
.
assertRaises
(
AssertionError
,
f
,
1
,
0
)
self
.
assertRaises
(
AssertionError
,
f
,
1
,
0
)
def
test1
(
self
):
def
test
_local_remove_useless_assert
1
(
self
):
#remove assert that are always true
#
remove assert that are always true
mode
=
theano
.
config
.
mode
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
mode
=
'FAST_RUN'
...
@@ -3239,8 +3239,8 @@ class test_assert(utt.InferShapeTester):
...
@@ -3239,8 +3239,8 @@ class test_assert(utt.InferShapeTester):
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
topo
[
0
]
.
op
==
deep_copy_op
assert
topo
[
0
]
.
op
==
deep_copy_op
def
test2
(
self
):
def
test
_test_local_remove_useless_assert
2
(
self
):
#remove assert condition that are always true
#
remove assert condition that are always true
mode
=
theano
.
config
.
mode
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
mode
=
'FAST_RUN'
...
@@ -3257,8 +3257,8 @@ class test_assert(utt.InferShapeTester):
...
@@ -3257,8 +3257,8 @@ class test_assert(utt.InferShapeTester):
assert
len
(
topo
[
0
]
.
inputs
)
==
2
assert
len
(
topo
[
0
]
.
inputs
)
==
2
assert
topo
[
1
]
.
op
==
deep_copy_op
assert
topo
[
1
]
.
op
==
deep_copy_op
def
test3
(
self
):
def
test
_local_remove_useless_assert
3
(
self
):
#don't remove assert condition that are always false
#
don't remove assert condition that are always false
mode
=
theano
.
config
.
mode
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
mode
=
'FAST_RUN'
...
@@ -3274,6 +3274,22 @@ class test_assert(utt.InferShapeTester):
...
@@ -3274,6 +3274,22 @@ class test_assert(utt.InferShapeTester):
assert
len
(
topo
[
0
]
.
inputs
)
==
3
assert
len
(
topo
[
0
]
.
inputs
)
==
3
assert
topo
[
1
]
.
op
==
deep_copy_op
assert
topo
[
1
]
.
op
==
deep_copy_op
def
test_local_remove_all_assert1
(
self
):
# remove assert condition that are unknown
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
mode
=
compile
.
mode
.
get_mode
(
mode
)
.
including
(
'local_remove_all_assert'
)
x
=
T
.
scalar
()
y
=
T
.
scalar
()
f
=
theano
.
function
([
x
,
y
],
theano
.
tensor
.
opt
.
assert_op
(
x
,
y
),
mode
=
mode
)
f
(
1
,
0
)
# Without opt, it should fail.
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
,
topo
assert
topo
[
0
]
.
op
==
deep_copy_op
,
topo
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
adscal
=
dscalar
()
adscal
=
dscalar
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论