Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
15bb0b8e
提交
15bb0b8e
authored
4月 19, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove Assert condition that are always true and remove Assert op that are always true. +test.
上级
71486d94
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
66 行增加
和
2 行删除
+66
-2
opt.py
theano/tensor/opt.py
+21
-2
test_opt.py
theano/tensor/tests/test_opt.py
+45
-0
没有找到文件。
theano/tensor/opt.py
浏览文件 @
15bb0b8e
...
@@ -660,6 +660,26 @@ class Assert(T.Op):
...
@@ -660,6 +660,26 @@ class Assert(T.Op):
assert_
=
Assert
()
assert_
=
Assert
()
@register_specialize
@gof.local_optimizer
([
Assert
])
def
local_remove_useless_assert
(
node
):
if
isinstance
(
node
.
op
,
Assert
):
cond
=
[]
for
c
in
node
.
inputs
[
1
:]:
try
:
const
=
get_constant_value
(
c
)
if
0
!=
const
.
ndim
or
const
==
0
:
#Should we raise an error here? How to be sure it is not catched?
cond
.
append
(
c
)
except
TypeError
:
cond
.
append
(
c
)
if
len
(
cond
)
==
0
:
return
[
node
.
inputs
[
0
]]
if
len
(
cond
)
!=
len
(
node
.
inputs
)
-
1
:
return
[
assert_
(
node
.
inputs
[
0
],
*
cond
)]
@gof.local_optimizer
([
T
.
Alloc
])
@gof.local_optimizer
([
T
.
Alloc
])
def
local_alloc_elemwise
(
node
):
def
local_alloc_elemwise
(
node
):
"""
"""
...
@@ -730,10 +750,9 @@ def local_alloc_elemwise(node):
...
@@ -730,10 +750,9 @@ def local_alloc_elemwise(node):
return
[
node
.
op
(
*
new
)]
return
[
node
.
op
(
*
new
)]
#TODO, T.eq if both input are the same, remove!
#TODO, T.eq if both input are the same, remove!
#TODO, op that check the condition are all true and remove the Assert. Also remove the constant condition.
#TODO, global optimizer that lift the assert to the beginning of the graph.
#TODO, global optimizer that lift the assert to the beginning of the graph.
#TODO, var.tag.shape to propagate the shape and lower the overhead of this op
#TODO, var.tag.shape to propagate the shape and lower the overhead of this op
#TODO, when all
can be optimizer
do all except one
#TODO, when all
inputs can be optimized
do all except one
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
"If True enable the experimental optimization local_alloc_elemwise"
,
"If True enable the experimental optimization local_alloc_elemwise"
,
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
15bb0b8e
...
@@ -1093,6 +1093,51 @@ class test_assert(unittest.TestCase):
...
@@ -1093,6 +1093,51 @@ class test_assert(unittest.TestCase):
f
(
1
,
1
)
f
(
1
,
1
)
self
.
failUnlessRaises
(
AssertionError
,
f
,
1
,
0
)
self
.
failUnlessRaises
(
AssertionError
,
f
,
1
,
0
)
def
test1
(
self
):
#remove assert that are always true
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
mode
=
compile
.
mode
.
get_mode
(
mode
)
x
=
T
.
scalar
()
f
=
theano
.
function
([
x
],
theano
.
tensor
.
opt
.
assert_
(
x
,
1
),
mode
=
mode
)
assert
f
(
1
)
==
1
assert
f
(
5
)
==
5
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
0
def
test2
(
self
):
#remove assert condition that are always true
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
mode
=
compile
.
mode
.
get_mode
(
mode
)
x
=
T
.
scalar
()
y
=
T
.
scalar
()
f
=
theano
.
function
([
x
,
y
],
theano
.
tensor
.
opt
.
assert_
(
x
,
y
,
1
),
mode
=
mode
)
assert
f
(
1
,
1
)
==
1
assert
f
(
5
,
1
)
==
5
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
[
0
]
.
inputs
)
==
2
def
test3
(
self
):
#don't remove assert condition that are always false
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
mode
=
compile
.
mode
.
get_mode
(
mode
)
x
=
T
.
scalar
()
y
=
T
.
scalar
()
f
=
theano
.
function
([
x
,
y
],
theano
.
tensor
.
opt
.
assert_
(
x
,
y
,
0
),
mode
=
mode
)
self
.
failUnlessRaises
(
AssertionError
,
f
,
1
,
0
)
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
[
0
]
.
inputs
)
==
3
def
test_local_mul_specialize
():
def
test_local_mul_specialize
():
# test a few cases to make sure that the basics are covered
# test a few cases to make sure that the basics are covered
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论