Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b7294365
提交
b7294365
authored
7月 09, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1376 from nouiz/fix_tests
Fix tests
上级
bbe32f5b
0d29731c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
62 行增加
和
36 行删除
+62
-36
test_lazy.py
theano/gof/tests/test_lazy.py
+55
-35
vm.py
theano/gof/vm.py
+1
-1
test_memory.py
theano/sandbox/cuda/tests/test_memory.py
+6
-0
没有找到文件。
theano/gof/tests/test_lazy.py
浏览文件 @
b7294365
...
@@ -2,6 +2,7 @@ from copy import deepcopy
...
@@ -2,6 +2,7 @@ from copy import deepcopy
import
numpy
import
numpy
import
theano
from
theano.gof.op
import
PureOp
from
theano.gof.op
import
PureOp
from
theano.gof
import
Apply
,
generic
,
Container
from
theano.gof
import
Apply
,
generic
,
Container
from
theano.gof.link
import
LocalLinker
,
map_storage
,
add_clear_storage
from
theano.gof.link
import
LocalLinker
,
map_storage
,
add_clear_storage
...
@@ -13,15 +14,16 @@ import theano.tensor as T
...
@@ -13,15 +14,16 @@ import theano.tensor as T
class
IfElseIfElseIf
(
PureOp
):
class
IfElseIfElseIf
(
PureOp
):
def
__init__
(
self
,
inplace
=
False
):
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
# check destroyhandler and others to ensure that a view_map with
# check destroyhandler and others to ensure that a view_map with
self
.
inplace
=
inplace
#multiple inputs can work
#multiple inputs can work
assert
not
self
.
inplace
assert
not
self
.
inplace
def
make_node
(
self
,
c1
,
t1
,
c2
,
t2
,
c3
,
t3
,
f3
):
def
make_node
(
self
,
c1
,
t1
,
c2
,
t2
,
c3
,
t3
,
f3
):
assert
t1
.
type
==
f3
.
type
assert
t1
.
type
==
f3
.
type
assert
t2
.
type
==
t3
.
type
assert
t2
.
type
==
t3
.
type
assert
t3
.
type
==
f3
.
type
assert
t3
.
type
==
f3
.
type
return
Apply
(
self
,
[
c1
,
t1
,
c2
,
t2
,
c3
,
t3
,
f3
],
[
t1
.
type
()])
return
Apply
(
self
,
[
c1
,
t1
,
c2
,
t2
,
c3
,
t3
,
f3
],
[
t1
.
type
()])
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
...
@@ -41,8 +43,9 @@ class IfElseIfElseIf(PureOp):
...
@@ -41,8 +43,9 @@ class IfElseIfElseIf(PureOp):
if
not
input_computed
[
1
][
0
]:
if
not
input_computed
[
1
][
0
]:
return
[
1
]
return
[
1
]
else
:
else
:
output_computed
[
0
][
0
]
=
1
output_computed
[
0
][
0
]
=
1
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
1
][
0
]))
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
1
][
0
]))
return
[]
return
[]
else
:
else
:
if
not
input_computed
[
2
][
0
]:
if
not
input_computed
[
2
][
0
]:
...
@@ -54,7 +57,8 @@ class IfElseIfElseIf(PureOp):
...
@@ -54,7 +57,8 @@ class IfElseIfElseIf(PureOp):
return
[
3
]
return
[
3
]
else
:
else
:
output_computed
[
0
][
0
]
=
1
output_computed
[
0
][
0
]
=
1
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
3
][
0
]))
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
3
][
0
]))
return
[]
return
[]
else
:
else
:
if
not
input_computed
[
4
][
0
]:
if
not
input_computed
[
4
][
0
]:
...
@@ -66,30 +70,33 @@ class IfElseIfElseIf(PureOp):
...
@@ -66,30 +70,33 @@ class IfElseIfElseIf(PureOp):
return
[
5
]
return
[
5
]
else
:
else
:
output_computed
[
0
][
0
]
=
1
output_computed
[
0
][
0
]
=
1
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
5
][
0
]))
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
5
][
0
]))
return
[]
return
[]
else
:
else
:
if
not
input_computed
[
6
][
0
]:
if
not
input_computed
[
6
][
0
]:
return
[
6
]
return
[
6
]
else
:
else
:
output_computed
[
0
][
0
]
=
1
output_computed
[
0
][
0
]
=
1
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
6
][
0
]))
output_registers
[
0
][
0
]
=
outtype
.
filter
(
deepcopy
(
input_registers
[
6
][
0
]))
return
[]
return
[]
thunk
.
lazy
=
True
thunk
.
lazy
=
True
return
thunk
return
thunk
class
NotImplementedOp
(
PureOp
):
class
NotImplementedOp
(
PureOp
):
class
E
(
Exception
):
pass
class
E
(
Exception
):
pass
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
):
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
def
thunk
():
def
thunk
():
raise
self
.
E
()
raise
self
.
E
()
thunk
.
lazy
=
False
thunk
.
lazy
=
False
return
thunk
return
thunk
...
@@ -99,22 +106,28 @@ def test_ifelse():
...
@@ -99,22 +106,28 @@ def test_ifelse():
c
=
generic
()
c
=
generic
()
notimpl
=
NotImplementedOp
()
notimpl
=
NotImplementedOp
()
lazys
=
[
True
]
f
=
function
([
a
,
b
,
c
],
ifelse
(
a
,
notimpl
(
b
),
c
),
# We need lazy to end up being True for this test.
mode
=
Mode
(
linker
=
'vm'
,
optimizer
=
'fast_run'
))
if
theano
.
config
.
vm
.
lazy
in
[
True
,
None
]:
lazys
=
[
True
,
None
]
try
:
for
cloop
in
[
True
,
False
]:
print
"case 1"
for
lazy
in
lazys
:
f
(
1
,
'a'
,
'b'
)
linker
=
theano
.
gof
.
vm
.
VM_Linker
(
use_cloop
=
cloop
,
lazy
=
lazy
)
assert
False
f
=
function
([
a
,
b
,
c
],
ifelse
(
a
,
notimpl
(
b
),
c
),
except
NotImplementedOp
.
E
:
mode
=
Mode
(
linker
=
linker
,
optimizer
=
'fast_run'
))
pass
print
"... passed"
try
:
print
"case 1"
print
"case 2"
f
(
1
,
'a'
,
'b'
)
print
f
(
0
,
'a'
,
'b'
)
assert
False
assert
f
(
0
,
'a'
,
'b'
)
==
'b'
except
NotImplementedOp
.
E
:
print
"... passed"
pass
print
"... passed"
print
"case 2"
print
f
(
0
,
'a'
,
'b'
)
assert
f
(
0
,
'a'
,
'b'
)
==
'b'
print
"... passed"
def
more_complex_test
():
def
more_complex_test
():
...
@@ -125,19 +138,26 @@ def more_complex_test():
...
@@ -125,19 +138,26 @@ def more_complex_test():
x2
=
T
.
scalar
(
'x2'
)
x2
=
T
.
scalar
(
'x2'
)
c1
=
T
.
scalar
(
'c1'
)
c1
=
T
.
scalar
(
'c1'
)
c2
=
T
.
scalar
(
'c2'
)
c2
=
T
.
scalar
(
'c2'
)
t1
=
ifelse
(
c1
,
x1
,
notimpl
(
x2
))
t1
=
ifelse
(
c1
,
x1
,
notimpl
(
x2
))
t1
.
name
=
't1'
t1
.
name
=
't1'
t2
=
t1
*
10
t2
=
t1
*
10
t2
.
name
=
't2'
t2
.
name
=
't2'
t3
=
ifelse
(
c2
,
t2
,
x1
+
t1
)
t3
=
ifelse
(
c2
,
t2
,
x1
+
t1
)
t3
.
name
=
't3'
t3
.
name
=
't3'
t4
=
ifelseifelseif
(
T
.
eq
(
x1
,
x2
),
x1
,
T
.
eq
(
x1
,
5
),
x2
,
c2
,
t3
,
t3
+
0.5
)
t4
=
ifelseifelseif
(
T
.
eq
(
x1
,
x2
),
x1
,
T
.
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'
))
f
=
function
([
c1
,
c2
,
x1
,
x2
],
t4
,
mode
=
Mode
(
linker
=
'vm'
,
optimizer
=
'fast_run'
))
print
f
(
1
,
0
,
numpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
if
theano
.
config
.
vm
.
lazy
is
False
:
assert
f
(
1
,
0
,
numpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
try
:
f
(
1
,
0
,
numpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
assert
False
except
NotImplementedOp
.
E
:
pass
else
:
print
f
(
1
,
0
,
numpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
assert
f
(
1
,
0
,
numpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
print
'... passed'
print
'... passed'
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
theano/gof/vm.py
浏览文件 @
b7294365
...
@@ -36,7 +36,7 @@ def filter_vm_lazy(val):
...
@@ -36,7 +36,7 @@ def filter_vm_lazy(val):
return
False
return
False
elif
val
==
'True'
or
val
is
True
:
elif
val
==
'True'
or
val
is
True
:
return
True
return
True
elif
val
==
'None'
:
elif
val
==
'None'
or
val
is
None
:
return
None
return
None
else
:
else
:
raise
ValueError
(
'Valid values for an vm.lazy parameter '
raise
ValueError
(
'Valid values for an vm.lazy parameter '
...
...
theano/sandbox/cuda/tests/test_memory.py
浏览文件 @
b7294365
import
copy
import
gc
import
gc
import
numpy
as
np
import
numpy
as
np
...
@@ -18,6 +19,11 @@ if theano.config.mode == 'FAST_COMPILE':
...
@@ -18,6 +19,11 @@ if theano.config.mode == 'FAST_COMPILE':
else
:
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
# The GC need to be enabled for those tests to work correctly.
if
not
getattr
(
mode_with_gpu
.
linker
,
'allow_gc'
,
False
):
mode_with_gpu
.
linker
=
copy
.
copy
(
mode_with_gpu
.
linker
)
mode_with_gpu
.
linker
.
allow_gc
=
True
def
freemem
(
extra_alloc
=
0
):
def
freemem
(
extra_alloc
=
0
):
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论