Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
792e615a
提交
792e615a
authored
4月 27, 2015
作者:
dima
提交者:
serdyuk
4月 29, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed formatting
Binary mode for zip Binary mode in tests
上级
839043bb
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
12 行增加
和
12 行删除
+12
-12
pkl_utils.py
theano/misc/pkl_utils.py
+8
-8
test_pkl_utils.py
theano/misc/tests/test_pkl_utils.py
+4
-4
没有找到文件。
theano/misc/pkl_utils.py
浏览文件 @
792e615a
...
...
@@ -136,7 +136,7 @@ class PersistentNdarrayID(object):
def
_resolve_name
(
self
,
obj
):
"""Determine the name the object should be saved under."""
name
=
'array_{}'
.
format
(
self
.
count
)
name
=
'array_{
0
}'
.
format
(
self
.
count
)
self
.
count
+=
1
return
name
...
...
@@ -147,7 +147,7 @@ class PersistentNdarrayID(object):
numpy
.
lib
.
format
.
write_array
(
f
,
obj
)
name
=
self
.
_resolve_name
(
obj
)
zipadd
(
write_array
,
self
.
zip_file
,
name
)
self
.
seen
[
id
(
obj
)]
=
'ndarray.{}'
.
format
(
name
)
self
.
seen
[
id
(
obj
)]
=
'ndarray.{
0
}'
.
format
(
name
)
return
self
.
seen
[
id
(
obj
)]
...
...
@@ -164,7 +164,7 @@ class PersistentCudaNdarrayID(PersistentNdarrayID):
numpy
.
lib
.
format
.
write_array
(
f
,
numpy
.
asarray
(
obj
))
name
=
self
.
_resolve_name
(
obj
)
zipadd
(
write_array
,
self
.
zip_file
,
name
)
self
.
seen
[
id
(
obj
)]
=
'cuda_ndarray.{}'
.
format
(
name
)
self
.
seen
[
id
(
obj
)]
=
'cuda_ndarray.{
0
}'
.
format
(
name
)
return
self
.
seen
[
id
(
obj
)]
super
(
PersistentCudaNdarrayID
,
self
)
.
__call__
(
obj
)
...
...
@@ -206,8 +206,8 @@ class PersistentSharedVariableID(PersistentCudaNdarrayID):
if
count
:
if
not
self
.
allow_duplicates
:
raise
ValueError
(
"multiple shared variables with the name "
"`{}` found"
.
format
(
name
))
name
=
'{
}_{
}'
.
format
(
name
,
count
+
1
)
"`{
0
}` found"
.
format
(
name
))
name
=
'{
0}_{1
}'
.
format
(
name
,
count
+
1
)
self
.
name_counter
[
name
]
+=
1
return
name
return
super
(
PersistentSharedVariableID
,
self
)
.
_resolve_name
(
obj
)
...
...
@@ -219,7 +219,7 @@ class PersistentSharedVariableID(PersistentCudaNdarrayID):
ValueError
(
"can't pickle shared variable with name `pkl`"
)
self
.
ndarray_names
[
id
(
obj
.
container
.
storage
[
0
])]
=
obj
.
name
elif
not
self
.
allow_unnamed
:
raise
ValueError
(
"unnamed shared variable, {}"
.
format
(
obj
))
raise
ValueError
(
"unnamed shared variable, {
0
}"
.
format
(
obj
))
return
super
(
PersistentSharedVariableID
,
self
)
.
__call__
(
obj
)
...
...
@@ -296,7 +296,7 @@ def dump(obj, file_handler, protocol=DEFAULT_PROTOCOL,
array(2)
"""
with
closing
(
zipfile
.
ZipFile
(
file_handler
,
'w'
,
zipfile
.
ZIP_DEFLATED
,
with
closing
(
zipfile
.
ZipFile
(
file_handler
,
'w
b
'
,
zipfile
.
ZIP_DEFLATED
,
allowZip64
=
True
))
as
zip_file
:
def
func
(
f
):
p
=
pickle
.
Pickler
(
f
,
protocol
=
protocol
)
...
...
@@ -317,7 +317,7 @@ def load(f, persistent_load=PersistentNdarrayLoad):
:type persistent_load: callable, optional
"""
with
closing
(
zipfile
.
ZipFile
(
f
,
'r'
))
as
zip_file
:
with
closing
(
zipfile
.
ZipFile
(
f
,
'r
b
'
))
as
zip_file
:
p
=
pickle
.
Unpickler
(
StringIO
(
zip_file
.
open
(
'pkl'
)
.
read
()))
p
.
persistent_load
=
persistent_load
(
zip_file
)
return
p
.
load
()
...
...
theano/misc/tests/test_pkl_utils.py
浏览文件 @
792e615a
...
...
@@ -18,10 +18,10 @@ def test_dump_load():
x
=
CudaNdarraySharedVariable
(
'x'
,
CudaNdarrayType
((
1
,
1
),
name
=
'x'
),
[[
1
]],
False
)
with
open
(
'test'
,
'w'
)
as
f
:
with
open
(
'test'
,
'w
b
'
)
as
f
:
dump
(
x
,
f
)
with
open
(
'test'
,
'r'
)
as
f
:
with
open
(
'test'
,
'r
b
'
)
as
f
:
x
=
load
(
f
)
assert
x
.
name
==
'x'
...
...
@@ -34,10 +34,10 @@ def test_dump_load_mrg():
rng
=
MRG_RandomStreams
(
use_cuda
=
True
)
with
open
(
'test'
,
'w'
)
as
f
:
with
open
(
'test'
,
'w
b
'
)
as
f
:
dump
(
rng
,
f
)
with
open
(
'test'
,
'r'
)
as
f
:
with
open
(
'test'
,
'r
b
'
)
as
f
:
rng
=
load
(
f
)
assert
type
(
rng
)
==
MRG_RandomStreams
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论