Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
adaea20e
提交
adaea20e
authored
7月 20, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flake8 for theano/gof/tests/test_graph.py
上级
3dc12504
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
39 行删除
+40
-39
test_graph.py
theano/gof/tests/test_graph.py
+40
-39
没有找到文件。
theano/gof/tests/test_graph.py
浏览文件 @
adaea20e
...
@@ -6,17 +6,16 @@ from itertools import count
...
@@ -6,17 +6,16 @@ from itertools import count
from
theano
import
(
from
theano
import
(
clone
,
sparse
,
sparse
,
shared
,
tensor
)
shared
,
tensor
)
from
theano.gof.graph
import
(
from
theano.gof.graph
import
(
Node
,
Apply
,
Constant
,
Apply
,
as_string
,
clone
,
general_toposort
,
inputs
,
io_toposort
,
as_string
,
clone
,
general_toposort
,
inputs
,
io_toposort
,
is_same_graph
,
Variable
)
is_same_graph
,
Variable
)
from
theano.gof.op
import
Op
from
theano.gof.op
import
Op
from
theano.gof.type
import
Type
from
theano.gof.type
import
Type
from
theano.tensor.var
import
TensorVariable
from
theano.sandbox.cuda.var
import
(
from
theano.sandbox.cuda.var
import
(
CudaNdarrayVariable
,
CudaNdarrayConstant
,
CudaNdarraySharedVariable
)
CudaNdarrayVariable
,
CudaNdarrayConstant
,
CudaNdarraySharedVariable
)
def
as_variable
(
x
):
def
as_variable
(
x
):
...
@@ -46,7 +45,7 @@ def MyVariable(thingy):
...
@@ -46,7 +45,7 @@ def MyVariable(thingy):
class
MyOp
(
Op
):
class
MyOp
(
Op
):
__props__
=
()
__props__
=
()
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
inputs
=
list
(
map
(
as_variable
,
inputs
))
inputs
=
list
(
map
(
as_variable
,
inputs
))
for
input
in
inputs
:
for
input
in
inputs
:
...
@@ -85,9 +84,11 @@ class TestInputs:
...
@@ -85,9 +84,11 @@ class TestInputs:
class
X
:
class
X
:
leaf_formatter
=
lambda
self
,
leaf
:
str
(
leaf
.
type
)
def
leaf_formatter
(
self
,
leaf
):
node_formatter
=
lambda
self
,
node
,
argstrings
:
"
%
s(
%
s)"
%
(
node
.
op
,
return
str
(
leaf
.
type
)
", "
.
join
(
argstrings
))
def
node_formatter
(
self
,
node
,
argstrings
):
return
"
%
s(
%
s)"
%
(
node
.
op
,
", "
.
join
(
argstrings
))
def
str
(
self
,
inputs
,
outputs
):
def
str
(
self
,
inputs
,
outputs
):
return
as_string
(
inputs
,
outputs
,
return
as_string
(
inputs
,
outputs
,
...
@@ -117,7 +118,7 @@ class TestStr(X):
...
@@ -117,7 +118,7 @@ class TestStr(X):
assert
self
.
str
([
r1
,
r2
,
r5
],
node2
.
outputs
)
==
[
"MyOp(*1 -> MyOp(R1, R2), *1)"
]
assert
self
.
str
([
r1
,
r2
,
r5
],
node2
.
outputs
)
==
[
"MyOp(*1 -> MyOp(R1, R2), *1)"
]
def
test_cutoff
(
self
):
def
test_cutoff
(
self
):
r1
,
r2
,
r5
=
MyVariable
(
1
),
MyVariable
(
2
),
MyVariable
(
5
)
r1
,
r2
=
MyVariable
(
1
),
MyVariable
(
2
)
node
=
MyOp
.
make_node
(
r1
,
r2
)
node
=
MyOp
.
make_node
(
r1
,
r2
)
node2
=
MyOp
.
make_node
(
node
.
outputs
[
0
],
node
.
outputs
[
0
])
node2
=
MyOp
.
make_node
(
node
.
outputs
[
0
],
node
.
outputs
[
0
])
assert
self
.
str
(
node
.
outputs
,
node2
.
outputs
)
==
[
"MyOp(R3, R3)"
]
assert
self
.
str
(
node
.
outputs
,
node2
.
outputs
)
==
[
"MyOp(R3, R3)"
]
...
@@ -185,7 +186,7 @@ class TestToposort:
...
@@ -185,7 +186,7 @@ class TestToposort:
def
test_1
(
self
):
def
test_1
(
self
):
"""Test a graph with double dependencies"""
"""Test a graph with double dependencies"""
r1
,
r
2
,
r5
=
MyVariable
(
1
),
MyVariable
(
2
),
MyVariable
(
5
)
r1
,
r
5
=
MyVariable
(
1
),
MyVariable
(
5
)
o
=
MyOp
.
make_node
(
r1
,
r1
)
o
=
MyOp
.
make_node
(
r1
,
r1
)
o2
=
MyOp
.
make_node
(
o
.
outputs
[
0
],
r5
)
o2
=
MyOp
.
make_node
(
o
.
outputs
[
0
],
r5
)
all
=
general_toposort
(
o2
.
outputs
,
prenode
)
all
=
general_toposort
(
o2
.
outputs
,
prenode
)
...
@@ -193,7 +194,7 @@ class TestToposort:
...
@@ -193,7 +194,7 @@ class TestToposort:
def
test_2
(
self
):
def
test_2
(
self
):
"""Test a graph where the inputs have owners"""
"""Test a graph where the inputs have owners"""
r1
,
r
2
,
r5
=
MyVariable
(
1
),
MyVariable
(
2
),
MyVariable
(
5
)
r1
,
r
5
=
MyVariable
(
1
),
MyVariable
(
5
)
o
=
MyOp
.
make_node
(
r1
,
r1
)
o
=
MyOp
.
make_node
(
r1
,
r1
)
r2b
=
o
.
outputs
[
0
]
r2b
=
o
.
outputs
[
0
]
o2
=
MyOp
.
make_node
(
r2b
,
r2b
)
o2
=
MyOp
.
make_node
(
r2b
,
r2b
)
...
@@ -214,7 +215,7 @@ class TestToposort:
...
@@ -214,7 +215,7 @@ class TestToposort:
def
test_4
(
self
):
def
test_4
(
self
):
"""Test inputs and outputs mixed together in a chain graph"""
"""Test inputs and outputs mixed together in a chain graph"""
r1
,
r2
,
r3
,
r4
=
MyVariable
(
1
),
MyVariable
(
2
),
MyVariable
(
3
),
MyVariable
(
4
)
r1
,
r2
=
MyVariable
(
1
),
MyVariable
(
2
)
o0
=
MyOp
.
make_node
(
r1
,
r2
)
o0
=
MyOp
.
make_node
(
r1
,
r2
)
o1
=
MyOp
.
make_node
(
o0
.
outputs
[
0
],
r1
)
o1
=
MyOp
.
make_node
(
o0
.
outputs
[
0
],
r1
)
all
=
io_toposort
([
r1
,
o0
.
outputs
[
0
]],
[
o0
.
outputs
[
0
],
o1
.
outputs
[
0
]])
all
=
io_toposort
([
r1
,
o0
.
outputs
[
0
]],
[
o0
.
outputs
[
0
],
o1
.
outputs
[
0
]])
...
@@ -222,9 +223,9 @@ class TestToposort:
...
@@ -222,9 +223,9 @@ class TestToposort:
def
test_5
(
self
):
def
test_5
(
self
):
"""Test when outputs have clients"""
"""Test when outputs have clients"""
r1
,
r2
,
r
3
,
r4
=
MyVariable
(
1
),
MyVariable
(
2
),
MyVariable
(
3
),
MyVariable
(
4
)
r1
,
r2
,
r
4
=
MyVariable
(
1
),
MyVariable
(
2
),
MyVariable
(
4
)
o0
=
MyOp
.
make_node
(
r1
,
r2
)
o0
=
MyOp
.
make_node
(
r1
,
r2
)
o1
=
MyOp
.
make_node
(
o0
.
outputs
[
0
],
r4
)
MyOp
.
make_node
(
o0
.
outputs
[
0
],
r4
)
all
=
io_toposort
([],
o0
.
outputs
)
all
=
io_toposort
([],
o0
.
outputs
)
assert
all
==
[
o0
]
assert
all
==
[
o0
]
...
@@ -264,11 +265,11 @@ class TestIsSameGraph(unittest.TestCase):
...
@@ -264,11 +265,11 @@ class TestIsSameGraph(unittest.TestCase):
"""
"""
x
,
y
,
z
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
)
x
,
y
,
z
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
)
self
.
check
([
self
.
check
([
(
x
,
x
,
(({},
True
),
)),
(
x
,
x
,
(({},
True
),
)),
(
x
,
y
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
,
y
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
,
tensor
.
neg
(
x
),
(({},
False
),
)),
(
x
,
tensor
.
neg
(
x
),
(({},
False
),
)),
(
x
,
tensor
.
neg
(
y
),
(({},
False
),
)),
(
x
,
tensor
.
neg
(
y
),
(({},
False
),
)),
])
])
def
test_full_graph
(
self
):
def
test_full_graph
(
self
):
"""
"""
...
@@ -277,14 +278,14 @@ class TestIsSameGraph(unittest.TestCase):
...
@@ -277,14 +278,14 @@ class TestIsSameGraph(unittest.TestCase):
x
,
y
,
z
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
)
x
,
y
,
z
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
)
t
=
x
*
y
t
=
x
*
y
self
.
check
([
self
.
check
([
(
x
*
2
,
x
*
2
,
(({},
True
),
)),
(
x
*
2
,
x
*
2
,
(({},
True
),
)),
(
x
*
2
,
y
*
2
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
*
2
,
y
*
2
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
*
2
,
y
*
2
,
(({},
False
),
({
x
:
y
},
True
),
)),
(
x
*
2
,
y
*
2
,
(({},
False
),
({
x
:
y
},
True
),
)),
(
x
*
2
,
y
*
3
,
(({},
False
),
({
y
:
x
},
False
),
)),
(
x
*
2
,
y
*
3
,
(({},
False
),
({
y
:
x
},
False
),
)),
(
t
*
2
,
z
*
2
,
(({},
False
),
({
t
:
z
},
True
),
)),
(
t
*
2
,
z
*
2
,
(({},
False
),
({
t
:
z
},
True
),
)),
(
t
*
2
,
z
*
2
,
(({},
False
),
({
z
:
t
},
True
),
)),
(
t
*
2
,
z
*
2
,
(({},
False
),
({
z
:
t
},
True
),
)),
(
x
*
(
y
*
z
),
(
x
*
y
)
*
z
,
(({},
False
),
)),
(
x
*
(
y
*
z
),
(
x
*
y
)
*
z
,
(({},
False
),
)),
])
])
def
test_merge_only
(
self
):
def
test_merge_only
(
self
):
"""
"""
...
@@ -293,15 +294,15 @@ class TestIsSameGraph(unittest.TestCase):
...
@@ -293,15 +294,15 @@ class TestIsSameGraph(unittest.TestCase):
x
,
y
,
z
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
)
x
,
y
,
z
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
)
t
=
x
*
y
t
=
x
*
y
self
.
check
([
self
.
check
([
(
x
,
t
,
(({},
False
),
({
t
:
x
},
True
))),
(
x
,
t
,
(({},
False
),
({
t
:
x
},
True
))),
(
t
*
2
,
x
*
2
,
(({},
False
),
({
t
:
x
},
True
),
)),
(
t
*
2
,
x
*
2
,
(({},
False
),
({
t
:
x
},
True
),
)),
(
x
*
x
,
x
*
y
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
*
x
,
x
*
y
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
*
x
,
x
*
y
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
*
x
,
x
*
y
,
(({},
False
),
({
y
:
x
},
True
),
)),
(
x
*
x
+
z
,
x
*
y
+
t
,
(({},
False
),
(
x
*
x
+
z
,
x
*
y
+
t
,
(({},
False
),
({
y
:
x
},
False
),
({
y
:
x
},
False
),
({
y
:
x
,
t
:
z
},
True
))),
({
y
:
x
,
t
:
z
},
True
))),
],
],
debug
=
False
)
debug
=
False
)
################
################
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论