Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
78fd7c53
提交
78fd7c53
authored
7月 07, 2011
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Restored assert removed in e53532fa0e76 => protocol 0 should not be used
anymore when pickling functions Fixed corresponding tests that were using protocol 0.
上级
667cfdda
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
27 行增加
和
10 行删除
+27
-10
test_function_module.py
theano/compile/tests/test_function_module.py
+3
-3
test_module.py
theano/compile/tests/test_module.py
+1
-1
singleton.py
theano/misc/singleton.py
+23
-6
没有找到文件。
theano/compile/tests/test_function_module.py
浏览文件 @
78fd7c53
...
@@ -429,7 +429,7 @@ class T_picklefunction(unittest.TestCase):
...
@@ -429,7 +429,7 @@ class T_picklefunction(unittest.TestCase):
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
try
:
try
:
g
=
cPickle
.
loads
(
cPickle
.
dumps
(
f
))
g
=
cPickle
.
loads
(
cPickle
.
dumps
(
f
,
protocol
=-
1
))
except
NotImplementedError
,
e
:
except
NotImplementedError
,
e
:
if
e
[
0
]
.
startswith
(
'DebugMode is not picklable'
):
if
e
[
0
]
.
startswith
(
'DebugMode is not picklable'
):
return
return
...
@@ -467,7 +467,7 @@ class T_picklefunction(unittest.TestCase):
...
@@ -467,7 +467,7 @@ class T_picklefunction(unittest.TestCase):
old_default_link
=
config
.
linker
old_default_link
=
config
.
linker
try
:
try
:
try
:
try
:
str_f
=
cPickle
.
dumps
(
f
)
str_f
=
cPickle
.
dumps
(
f
,
protocol
=-
1
)
config
.
mode
=
'Mode'
config
.
mode
=
'Mode'
config
.
linker
=
'py'
config
.
linker
=
'py'
config
.
optimizer
=
'None'
config
.
optimizer
=
'None'
...
@@ -527,7 +527,7 @@ class T_picklefunction(unittest.TestCase):
...
@@ -527,7 +527,7 @@ class T_picklefunction(unittest.TestCase):
# try to pickle the entire things
# try to pickle the entire things
try
:
try
:
saved_format
=
cPickle
.
dumps
(
list_of_things
)
saved_format
=
cPickle
.
dumps
(
list_of_things
,
protocol
=-
1
)
new_list_of_things
=
cPickle
.
loads
(
saved_format
)
new_list_of_things
=
cPickle
.
loads
(
saved_format
)
except
NotImplementedError
,
e
:
except
NotImplementedError
,
e
:
if
e
[
0
]
.
startswith
(
'DebugMode is not picklable'
):
if
e
[
0
]
.
startswith
(
'DebugMode is not picklable'
):
...
...
theano/compile/tests/test_module.py
浏览文件 @
78fd7c53
...
@@ -700,7 +700,7 @@ def test_pickle():
...
@@ -700,7 +700,7 @@ def test_pickle():
mode
=
get_mode
()
mode
=
get_mode
()
m
=
M
.
make
(
x
=
numpy
.
zeros
((
4
,
5
)),
y
=
numpy
.
ones
((
2
,
3
)),
mode
=
mode
)
m
=
M
.
make
(
x
=
numpy
.
zeros
((
4
,
5
)),
y
=
numpy
.
ones
((
2
,
3
)),
mode
=
mode
)
m_dup
=
cPickle
.
loads
(
cPickle
.
dumps
(
m
))
m_dup
=
cPickle
.
loads
(
cPickle
.
dumps
(
m
,
protocol
=-
1
))
assert
numpy
.
all
(
m
.
x
==
m_dup
.
x
)
and
numpy
.
all
(
m
.
y
==
m_dup
.
y
)
assert
numpy
.
all
(
m
.
x
==
m_dup
.
x
)
and
numpy
.
all
(
m
.
y
==
m_dup
.
y
)
...
...
theano/misc/singleton.py
浏览文件 @
78fd7c53
...
@@ -49,14 +49,31 @@ class DeepCopiableFunction(Singleton):
...
@@ -49,14 +49,31 @@ class DeepCopiableFunction(Singleton):
if
type
(
self
)
!=
type
(
other
):
if
type
(
self
)
!=
type
(
other
):
return
False
return
False
# Since it is a singleton there should be no two different instances
# Since it is a singleton there should be no two different instances
# of this class. However it looks like this can actually happen under
# of this class.
# Linux when pickling with protocol 0 => need to look into this. Until
assert
self
is
other
# then, the assert below is commented and it might happen that two
# instances actually exist (which should not be an issue unless someone
# does a comparison with the 'is' operator).
#assert self is other
return
True
return
True
def
__hash__
(
self
):
def
__hash__
(
self
):
# Required for Ops that contain such functions.
# Required for Ops that contain such functions.
return
hash
(
type
(
self
))
return
hash
(
type
(
self
))
def
__getstate__
(
self
):
# Only implemented to ensure __setstate__ will always be called
# after unpickling such an object, even when __dict__ is empty.
if
self
.
__dict__
:
return
self
.
__dict__
else
:
# We need to make sure we return a value whose boolean cast is not
# False, otherwise __setstate__ will not be called.
return
True
def
__setstate__
(
self
,
state
):
# Only implemented to enforce the "singletonness" of this class.
if
state
is
not
True
:
self
.
__dict__
.
update
(
state
)
if
self
is
not
type
(
self
)
.
_instance
:
raise
AssertionError
(
"Unpickling a singleton should yield this singleton. If "
"this is not the case, you may have pickled it with "
"protocol 0. You will need to use a higher protocol to "
"properly unpickle this object."
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论