Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d95e8b6c
提交
d95e8b6c
authored
8月 26, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renamed _test_ext
上级
213db8fd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
146 行增加
和
129 行删除
+146
-129
_test_destroyhandler.py
gof/_test_destroyhandler.py
+146
-129
ext.py
gof/ext.py
+0
-0
没有找到文件。
gof/_test_
ext
.py
→
gof/_test_
destroyhandler
.py
浏览文件 @
d95e8b6c
...
@@ -8,6 +8,7 @@ from op import Op
...
@@ -8,6 +8,7 @@ from op import Op
from
opt
import
*
from
opt
import
*
from
ext
import
*
from
ext
import
*
import
destroyhandler
from
env
import
Env
,
InconsistencyError
from
env
import
Env
,
InconsistencyError
from
toolbox
import
ReplaceValidate
from
toolbox
import
ReplaceValidate
...
@@ -79,7 +80,9 @@ _Env = Env
...
@@ -79,7 +80,9 @@ _Env = Env
def
Env
(
inputs
,
outputs
,
validate
=
True
):
def
Env
(
inputs
,
outputs
,
validate
=
True
):
e
=
_Env
(
inputs
,
outputs
)
e
=
_Env
(
inputs
,
outputs
)
##e.extend(EquivTool(e))
##e.extend(EquivTool(e))
e
.
extend
(
DestroyHandler
())
e
.
extend
(
destroyhandler
.
DestroyHandler
())
e
.
extend
(
ReplaceValidate
())
e
.
extend
(
ReplaceValidate
())
if
validate
:
if
validate
:
e
.
validate
()
e
.
validate
()
...
@@ -95,26 +98,65 @@ class FailureWatch:
...
@@ -95,26 +98,65 @@ class FailureWatch:
self
.
failures
+=
1
self
.
failures
+=
1
class
_test_all
(
unittest
.
TestCase
):
class
_test_protocol
(
unittest
.
TestCase
):
def
test_misc
(
self
):
def
test_multi_destroyers
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
add
(
add_in_place
(
x
,
y
),
add_in_place
(
x
,
y
))
e
=
transpose_view
(
transpose_view
(
transpose_view
(
transpose_view
(
x
))))
try
:
g
=
Env
([
x
,
y
,
z
],
[
e
])
g
=
Env
([
x
,
y
,
z
],
[
e
])
assert
g
.
consistent
()
self
.
fail
()
chk
=
g
.
checkpoint
()
except
InconsistencyError
,
e
:
PatternOptimizer
((
transpose_view
,
(
transpose_view
,
'x'
)),
'x'
)
.
optimize
(
g
)
pass
assert
str
(
g
)
==
"[x]"
new_e
=
add
(
x
,
y
)
g
.
replace_validate
(
x
,
new_e
)
assert
str
(
g
)
==
"[Add(x, y)]"
g
.
replace
(
new_e
,
dot
(
add_in_place
(
x
,
y
),
transpose_view
(
x
)))
assert
str
(
g
)
==
"[Dot(AddInPlace(x, y), TransposeView(x))]"
assert
not
g
.
consistent
()
g
.
revert
(
chk
)
assert
g
.
consistent
()
assert
str
(
g
)
==
"[TransposeView(TransposeView(TransposeView(TransposeView(x))))]"
def
test_multi_destroyers_through_views
(
self
):
class
_test_protocol_skip
(
unittest
.
TestCase
):
def
test_aliased_inputs_replacement
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
dot
(
add
(
transpose_view
(
z
),
y
),
add
(
z
,
x
))
tv
=
transpose_view
(
x
)
g
=
Env
([
x
,
y
,
z
],
[
e
])
tvv
=
transpose_view
(
tv
)
sx
=
sigmoid
(
x
)
e
=
add_in_place
(
x
,
tv
)
g
=
Env
([
x
,
y
],
[
e
],
False
)
assert
not
g
.
consistent
()
g
.
replace
(
tv
,
sx
)
assert
g
.
consistent
()
assert
g
.
consistent
()
fail
=
FailureWatch
()
g
.
replace
(
sx
,
tv
)
OpSubOptimizer
(
add
,
add_in_place
,
fail
)
.
optimize
(
g
)
assert
not
g
.
consistent
()
g
.
replace
(
tv
,
tvv
)
assert
not
g
.
consistent
()
g
.
replace
(
tv
,
sx
)
assert
g
.
consistent
()
assert
g
.
consistent
()
assert
fail
.
failures
==
1
# should have succeeded once and failed once
def
test_indestructible
(
self
):
x
,
y
,
z
=
inputs
()
x
.
tag
.
indestructible
=
True
x
=
copy
(
x
)
assert
x
.
tag
.
indestructible
# checking if indestructible survives the copy!
e
=
add_in_place
(
x
,
y
)
g
=
Env
([
x
,
y
,
z
],
[
e
],
False
)
assert
not
g
.
consistent
()
g
.
replace_validate
(
e
,
add
(
x
,
y
))
assert
g
.
consistent
()
def
test_usage_loop_through_views_2
(
self
):
x
,
y
,
z
=
inputs
()
e0
=
transpose_view
(
transpose_view
(
sigmoid
(
x
)))
e
=
dot
(
add_in_place
(
x
,
y
),
transpose_view
(
e0
))
g
=
Env
([
x
,
y
,
z
],
[
e
])
assert
g
.
consistent
()
# because sigmoid can do the copy
# print g
# print g.destroy_handler.children
g
.
replace
(
e0
,
x
)
assert
not
g
.
consistent
()
# we cut off the path to the sigmoid
def
test_destroyers_loop
(
self
):
def
test_destroyers_loop
(
self
):
# AddInPlace(x, y) and AddInPlace(y, x) should not coexist
# AddInPlace(x, y) and AddInPlace(y, x) should not coexist
...
@@ -142,86 +184,32 @@ class _test_all(unittest.TestCase):
...
@@ -142,86 +184,32 @@ class _test_all(unittest.TestCase):
pass
pass
assert
g
.
consistent
()
assert
g
.
consistent
()
def
test_long_destroyers_loop
(
self
):
x
,
y
,
z
=
inputs
()
e
=
dot
(
dot
(
add_in_place
(
x
,
y
),
add_in_place
(
y
,
z
)),
add
(
z
,
x
))
g
=
Env
([
x
,
y
,
z
],
[
e
])
assert
g
.
consistent
()
OpSubOptimizer
(
add
,
add_in_place
)
.
optimize
(
g
)
assert
g
.
consistent
()
assert
str
(
g
)
!=
"[Dot(Dot(AddInPlace(x, y), AddInPlace(y, z)), AddInPlace(z, x))]"
# we don't want to see that!
e2
=
dot
(
dot
(
add_in_place
(
x
,
y
),
add_in_place
(
y
,
z
)),
add_in_place
(
z
,
x
))
try
:
g2
=
Env
(
*
graph
.
clone
([
x
,
y
,
z
],
[
e2
]))
self
.
fail
()
except
InconsistencyError
:
pass
def
test_usage_loop
(
self
):
class
_test_0
(
unittest
.
TestCase
):
x
,
y
,
z
=
inputs
()
g
=
Env
([
x
,
y
,
z
],
[
dot
(
add_in_place
(
x
,
z
),
x
)],
False
)
assert
not
g
.
consistent
()
OpSubOptimizer
(
add_in_place
,
add
)
.
optimize
(
g
)
# replace add_in_place with add
assert
g
.
consistent
()
def
test_
usage_loop_through_view
s
(
self
):
def
test_
aliased_input
s
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
aip
=
add_in_place
(
x
,
y
)
e
=
add_in_place
(
x
,
x
)
e
=
dot
(
aip
,
transpose_view
(
x
))
g
=
Env
([
x
],
[
e
],
False
)
g
=
Env
([
x
,
y
,
z
],
[
e
],
False
)
assert
not
g
.
consistent
()
assert
not
g
.
consistent
()
g
.
replace_validate
(
aip
,
add
(
x
,
z
))
assert
g
.
consistent
()
def
test_usage_loop_through_views_2
(
self
):
def
test_aliased_inputs2
(
self
):
x
,
y
,
z
=
inputs
()
e0
=
transpose_view
(
transpose_view
(
sigmoid
(
x
)))
e
=
dot
(
add_in_place
(
x
,
y
),
transpose_view
(
e0
))
g
=
Env
([
x
,
y
,
z
],
[
e
])
assert
g
.
consistent
()
# because sigmoid can do the copy
# print g
# print g.destroy_handler.children
g
.
replace
(
e0
,
x
)
assert
not
g
.
consistent
()
# we cut off the path to the sigmoid
def
test_usage_loop_insert_views
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
dot
(
add_in_place
(
x
,
add
(
y
,
z
)),
sigmoid
(
sigmoid
(
sigmoid
(
sigmoid
(
sigmoid
(
x
))))))
e
=
add_in_place
(
x
,
transpose_view
(
x
))
g
=
Env
([
x
,
y
,
z
],
[
e
])
g
=
Env
([
x
],
[
e
],
False
)
assert
g
.
consistent
()
assert
not
g
.
consistent
()
fail
=
FailureWatch
()
OpSubOptimizer
(
sigmoid
,
transpose_view
,
fail
)
.
optimize
(
g
)
assert
g
.
consistent
()
assert
fail
.
failures
==
1
# it must keep one sigmoid in the long sigmoid chain
def
test_
misc
(
self
):
def
test_
aliased_inputs_tolerate
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
transpose_view
(
transpose_view
(
transpose_view
(
transpose_view
(
x
))))
e
=
add_in_place_2
(
x
,
x
)
g
=
Env
([
x
,
y
,
z
],
[
e
])
g
=
Env
([
x
],
[
e
],
False
)
assert
g
.
consistent
()
chk
=
g
.
checkpoint
()
PatternOptimizer
((
transpose_view
,
(
transpose_view
,
'x'
)),
'x'
)
.
optimize
(
g
)
assert
str
(
g
)
==
"[x]"
new_e
=
add
(
x
,
y
)
g
.
replace_validate
(
x
,
new_e
)
assert
str
(
g
)
==
"[Add(x, y)]"
g
.
replace
(
new_e
,
dot
(
add_in_place
(
x
,
y
),
transpose_view
(
x
)))
assert
str
(
g
)
==
"[Dot(AddInPlace(x, y), TransposeView(x))]"
assert
not
g
.
consistent
()
g
.
revert
(
chk
)
assert
g
.
consistent
()
assert
g
.
consistent
()
assert
str
(
g
)
==
"[TransposeView(TransposeView(TransposeView(TransposeView(x))))]"
def
test_
indestructible
(
self
):
def
test_
aliased_inputs_tolerate2
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
x
.
tag
.
indestructible
=
True
e
=
add_in_place_2
(
x
,
transpose_view
(
x
))
x
=
copy
(
x
)
g
=
Env
([
x
],
[
e
],
False
)
assert
x
.
tag
.
indestructible
# checking if indestructible survives the copy!
e
=
add_in_place
(
x
,
y
)
g
=
Env
([
x
,
y
,
z
],
[
e
],
False
)
assert
not
g
.
consistent
()
assert
not
g
.
consistent
()
g
.
replace_validate
(
e
,
add
(
x
,
y
))
assert
g
.
consistent
()
def
test_indestructible_through_views
(
self
):
def
test_indestructible_through_views
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
...
@@ -233,17 +221,6 @@ class _test_all(unittest.TestCase):
...
@@ -233,17 +221,6 @@ class _test_all(unittest.TestCase):
g
.
replace_validate
(
tv
,
sigmoid
(
x
))
g
.
replace_validate
(
tv
,
sigmoid
(
x
))
assert
g
.
consistent
()
assert
g
.
consistent
()
def
test_repair_destroy_path
(
self
):
x
,
y
,
z
=
inputs
()
e1
=
transpose_view
(
transpose_view
(
x
))
e2
=
transpose_view
(
transpose_view
(
e1
))
e3
=
add_in_place
(
e2
,
y
)
e4
=
add_in_place
(
e1
,
z
)
g
=
Env
([
x
,
y
,
z
],
[
e3
,
e4
],
False
)
assert
not
g
.
consistent
()
g
.
replace
(
e2
,
transpose_view
(
x
))
assert
not
g
.
consistent
()
def
test_indirect
(
self
):
def
test_indirect
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e0
=
add_in_place
(
x
,
y
)
e0
=
add_in_place
(
x
,
y
)
...
@@ -266,46 +243,86 @@ class _test_all(unittest.TestCase):
...
@@ -266,46 +243,86 @@ class _test_all(unittest.TestCase):
g
.
replace
(
e0
,
new_e0
)
g
.
replace
(
e0
,
new_e0
)
assert
g
.
consistent
()
assert
g
.
consistent
()
def
test_
aliased_inputs
(
self
):
def
test_
long_destroyers_loop
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
add_in_place
(
x
,
x
)
e
=
dot
(
dot
(
add_in_place
(
x
,
y
),
add_in_place
(
y
,
z
)),
add
(
z
,
x
))
g
=
Env
([
x
],
[
e
],
False
)
g
=
Env
([
x
,
y
,
z
],
[
e
])
assert
not
g
.
consistent
()
assert
g
.
consistent
()
OpSubOptimizer
(
add
,
add_in_place
)
.
optimize
(
g
)
assert
g
.
consistent
()
assert
str
(
g
)
!=
"[Dot(Dot(AddInPlace(x, y), AddInPlace(y, z)), AddInPlace(z, x))]"
# we don't want to see that!
e2
=
dot
(
dot
(
add_in_place
(
x
,
y
),
add_in_place
(
y
,
z
)),
add_in_place
(
z
,
x
))
try
:
g2
=
Env
(
*
graph
.
clone
([
x
,
y
,
z
],
[
e2
]))
self
.
fail
()
except
InconsistencyError
:
pass
def
test_
aliased_inputs
2
(
self
):
def
test_
misc_
2
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
add_in_place
(
x
,
transpose_view
(
x
))
tv
=
transpose_view
(
x
)
g
=
Env
([
x
],
[
e
],
False
)
e
=
add_in_place
(
x
,
tv
)
g
=
Env
([
x
,
y
],
[
e
],
False
)
assert
not
g
.
consistent
()
g
.
replace
(
tv
,
x
)
assert
not
g
.
consistent
()
assert
not
g
.
consistent
()
def
test_
aliased_inputs_tolerate
(
self
):
def
test_
multi_destroyers
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
add_in_place_2
(
x
,
x
)
e
=
add
(
add_in_place
(
x
,
y
),
add_in_place
(
x
,
y
))
g
=
Env
([
x
],
[
e
],
False
)
try
:
g
=
Env
([
x
,
y
,
z
],
[
e
])
self
.
fail
()
except
InconsistencyError
,
e
:
pass
def
test_multi_destroyers_through_views
(
self
):
x
,
y
,
z
=
inputs
()
e
=
dot
(
add
(
transpose_view
(
z
),
y
),
add
(
z
,
x
))
g
=
Env
([
x
,
y
,
z
],
[
e
])
assert
g
.
consistent
()
fail
=
FailureWatch
()
OpSubOptimizer
(
add
,
add_in_place
,
fail
)
.
optimize
(
g
)
assert
g
.
consistent
()
assert
g
.
consistent
()
assert
fail
.
failures
==
1
# should have succeeded once and failed once
def
test_aliased_inputs_tolerate2
(
self
):
def
test_repair_destroy_path
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
add_in_place_2
(
x
,
transpose_view
(
x
))
e1
=
transpose_view
(
transpose_view
(
x
))
g
=
Env
([
x
],
[
e
],
False
)
e2
=
transpose_view
(
transpose_view
(
e1
))
e3
=
add_in_place
(
e2
,
y
)
e4
=
add_in_place
(
e1
,
z
)
g
=
Env
([
x
,
y
,
z
],
[
e3
,
e4
],
False
)
assert
not
g
.
consistent
()
g
.
replace
(
e2
,
transpose_view
(
x
))
assert
not
g
.
consistent
()
assert
not
g
.
consistent
()
def
test_
aliased_inputs_replacement
(
self
):
def
test_
usage_loop
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
tv
=
transpose_view
(
x
)
g
=
Env
([
x
,
y
,
z
],
[
dot
(
add_in_place
(
x
,
z
),
x
)],
False
)
tvv
=
transpose_view
(
tv
)
sx
=
sigmoid
(
x
)
e
=
add_in_place
(
x
,
tv
)
g
=
Env
([
x
,
y
],
[
e
],
False
)
assert
not
g
.
consistent
()
assert
not
g
.
consistent
()
g
.
replace
(
tv
,
sx
)
OpSubOptimizer
(
add_in_place
,
add
)
.
optimize
(
g
)
# replace add_in_place with add
assert
g
.
consistent
()
assert
g
.
consistent
()
g
.
replace
(
sx
,
tv
)
assert
not
g
.
consistent
()
def
test_usage_loop_through_views
(
self
):
g
.
replace
(
tv
,
tvv
)
x
,
y
,
z
=
inputs
()
aip
=
add_in_place
(
x
,
y
)
e
=
dot
(
aip
,
transpose_view
(
x
))
g
=
Env
([
x
,
y
,
z
],
[
e
],
False
)
assert
not
g
.
consistent
()
assert
not
g
.
consistent
()
g
.
replace
(
tv
,
sx
)
g
.
replace_validate
(
aip
,
add
(
x
,
z
))
assert
g
.
consistent
()
def
test_usage_loop_insert_views
(
self
):
x
,
y
,
z
=
inputs
()
e
=
dot
(
add_in_place
(
x
,
add
(
y
,
z
)),
sigmoid
(
sigmoid
(
sigmoid
(
sigmoid
(
sigmoid
(
x
))))))
g
=
Env
([
x
,
y
,
z
],
[
e
])
assert
g
.
consistent
()
fail
=
FailureWatch
()
OpSubOptimizer
(
sigmoid
,
transpose_view
,
fail
)
.
optimize
(
g
)
assert
g
.
consistent
()
assert
g
.
consistent
()
assert
fail
.
failures
==
1
# it must keep one sigmoid in the long sigmoid chain
def
test_value_repl
(
self
):
def
test_value_repl
(
self
):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
...
@@ -325,17 +342,17 @@ class _test_all(unittest.TestCase):
...
@@ -325,17 +342,17 @@ class _test_all(unittest.TestCase):
g
.
replace
(
sy
,
transpose_view
(
MyValue
(
"abc"
)))
g
.
replace
(
sy
,
transpose_view
(
MyValue
(
"abc"
)))
assert
g
.
consistent
()
assert
g
.
consistent
()
def
test_misc_2
(
self
):
pass
x
,
y
,
z
=
inputs
()
tv
=
transpose_view
(
x
)
e
=
add_in_place
(
x
,
tv
)
g
=
Env
([
x
,
y
],
[
e
],
False
)
assert
not
g
.
consistent
()
g
.
replace
(
tv
,
x
)
assert
not
g
.
consistent
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
if
1
:
unittest
.
main
()
else
:
testcase
=
_test_protocol
suite
=
unittest
.
TestLoader
()
suite
=
suite
.
loadTestsFromTestCase
(
testcase
)
unittest
.
TextTestRunner
(
verbosity
=
2
)
.
run
(
suite
)
gof/ext.py
deleted
100644 → 0
浏览文件 @
213db8fd
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论