Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
27f80b39
提交
27f80b39
authored
10月 18, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor tests.gof.test_lazy and enable an incorrectly named test
上级
50ab0430
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
30 行删除
+23
-30
test_lazy.py
tests/gof/test_lazy.py
+23
-30
没有找到文件。
tests/gof/test_lazy.py
浏览文件 @
27f80b39
from
copy
import
deepcopy
import
pytest
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
from
theano.gof.op
import
PureOp
import
theano.tensor
as
tt
from
theano.gof
import
Apply
,
generic
from
copy
import
deepcopy
from
theano
import
function
,
Mode
from
theano
import
function
,
Mode
from
theano.gof
import
Apply
,
generic
from
theano.gof.op
import
PureOp
from
theano.ifelse
import
ifelse
from
theano.ifelse
import
ifelse
import
theano.tensor
as
tt
class
IfElseIfElseIf
(
PureOp
):
class
IfElseIfElseIf
(
PureOp
):
...
@@ -88,16 +91,17 @@ class IfElseIfElseIf(PureOp):
...
@@ -88,16 +91,17 @@ class IfElseIfElseIf(PureOp):
return
thunk
return
thunk
class
NotImplementedOp
(
PureOp
):
class
NotImplementedOpException
(
Exception
):
class
E
(
Exception
):
pass
pass
class
NotImplementedOp
(
PureOp
):
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
,
impl
):
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
,
impl
):
def
thunk
():
def
thunk
():
raise
self
.
E
()
raise
NotImplementedOpException
()
thunk
.
lazy
=
False
thunk
.
lazy
=
False
return
thunk
return
thunk
...
@@ -109,13 +113,17 @@ def test_ifelse():
...
@@ -109,13 +113,17 @@ def test_ifelse():
c
=
generic
()
c
=
generic
()
notimpl
=
NotImplementedOp
()
notimpl
=
NotImplementedOp
()
lazys
=
[
True
]
lazys
=
[
True
]
# We need lazy to end up being True for this test.
# We need lazy to end up being True for this test.
if
theano
.
config
.
vm
.
lazy
in
[
True
,
None
]:
if
theano
.
config
.
vm
.
lazy
in
[
True
,
None
]:
lazys
=
[
True
,
None
]
lazys
=
[
True
,
None
]
cloops
=
[
True
,
False
]
cloops
=
[
True
,
False
]
if
theano
.
config
.
cxx
==
""
:
if
theano
.
config
.
cxx
==
""
:
cloops
=
[
False
]
cloops
=
[
False
]
for
cloop
in
cloops
:
for
cloop
in
cloops
:
for
lazy
in
lazys
:
for
lazy
in
lazys
:
linker
=
theano
.
gof
.
vm
.
VM_Linker
(
use_cloop
=
cloop
,
lazy
=
lazy
)
linker
=
theano
.
gof
.
vm
.
VM_Linker
(
use_cloop
=
cloop
,
lazy
=
lazy
)
...
@@ -125,21 +133,13 @@ def test_ifelse():
...
@@ -125,21 +133,13 @@ def test_ifelse():
mode
=
Mode
(
linker
=
linker
,
optimizer
=
"fast_run"
),
mode
=
Mode
(
linker
=
linker
,
optimizer
=
"fast_run"
),
)
)
try
:
with
pytest
.
raises
(
NotImplementedOpException
):
# print "case 1"
f
(
1
,
"a"
,
"b"
)
f
(
1
,
"a"
,
"b"
)
assert
False
except
NotImplementedOp
.
E
:
pass
# print "... passed"
# print "case 2"
# print f(0, 'a', 'b')
assert
f
(
0
,
"a"
,
"b"
)
==
"b"
assert
f
(
0
,
"a"
,
"b"
)
==
"b"
# print "... passed"
def
more_complex_test
():
def
test_nested
():
notimpl
=
NotImplementedOp
()
notimpl
=
NotImplementedOp
()
ifelseifelseif
=
IfElseIfElseIf
()
ifelseifelseif
=
IfElseIfElseIf
()
...
@@ -156,18 +156,11 @@ def more_complex_test():
...
@@ -156,18 +156,11 @@ def more_complex_test():
t4
=
ifelseifelseif
(
tt
.
eq
(
x1
,
x2
),
x1
,
tt
.
eq
(
x1
,
5
),
x2
,
c2
,
t3
,
t3
+
0.5
)
t4
=
ifelseifelseif
(
tt
.
eq
(
x1
,
x2
),
x1
,
tt
.
eq
(
x1
,
5
),
x2
,
c2
,
t3
,
t3
+
0.5
)
t4
.
name
=
"t4"
t4
.
name
=
"t4"
f
=
function
([
c1
,
c2
,
x1
,
x2
],
t4
,
mode
=
Mode
(
linker
=
"vm"
,
optimizer
=
"fast_run"
)
)
linker
=
theano
.
gof
.
vm
.
VM_Linker
(
lazy
=
False
)
if
theano
.
config
.
vm
.
lazy
is
False
:
f
=
function
([
c1
,
c2
,
x1
,
x2
],
t4
,
mode
=
Mode
(
linker
=
linker
,
optimizer
=
"fast_run"
))
try
:
with
pytest
.
raises
(
NotImplementedOpException
)
:
f
(
1
,
0
,
np
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
f
(
1
,
0
,
np
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
assert
False
except
NotImplementedOp
.
E
:
pass
else
:
print
(
f
(
1
,
0
,
np
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
))
assert
f
(
1
,
0
,
np
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
print
(
"... passed"
)
linker
=
theano
.
gof
.
vm
.
VM_Linker
(
lazy
=
True
)
if
__name__
==
"__main__"
:
f
=
function
([
c1
,
c2
,
x1
,
x2
],
t4
,
mode
=
Mode
(
linker
=
linker
,
optimizer
=
"fast_run"
))
more_complex_test
()
assert
f
(
1
,
0
,
np
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论