Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1d7141d1
提交
1d7141d1
authored
4月 27, 2015
作者:
serdyuk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Zip files not in binary format
Binary mode for test files Added import Reading in binary mode Used BytesIO
上级
533d889b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
6 行删除
+7
-6
pkl_utils.py
theano/misc/pkl_utils.py
+5
-4
test_pkl_utils.py
theano/misc/tests/test_pkl_utils.py
+2
-2
没有找到文件。
theano/misc/pkl_utils.py
浏览文件 @
1d7141d1
...
@@ -5,6 +5,7 @@ These pickled graphs can be used, for instance, as cases for
...
@@ -5,6 +5,7 @@ These pickled graphs can be used, for instance, as cases for
unit tests or regression tests.
unit tests or regression tests.
"""
"""
import
numpy
import
numpy
import
os
import
pickle
import
pickle
import
sys
import
sys
import
tempfile
import
tempfile
...
@@ -13,7 +14,7 @@ import warnings
...
@@ -13,7 +14,7 @@ import warnings
from
collections
import
defaultdict
from
collections
import
defaultdict
from
contextlib
import
closing
from
contextlib
import
closing
from
pickle
import
HIGHEST_PROTOCOL
from
pickle
import
HIGHEST_PROTOCOL
from
theano.compat.six
import
String
IO
from
theano.compat.six
import
Bytes
IO
try
:
try
:
from
pickle
import
DEFAULT_PROTOCOL
from
pickle
import
DEFAULT_PROTOCOL
except
ImportError
:
except
ImportError
:
...
@@ -296,7 +297,7 @@ def dump(obj, file_handler, protocol=DEFAULT_PROTOCOL,
...
@@ -296,7 +297,7 @@ def dump(obj, file_handler, protocol=DEFAULT_PROTOCOL,
array(2)
array(2)
"""
"""
with
closing
(
zipfile
.
ZipFile
(
file_handler
,
'w
b
'
,
zipfile
.
ZIP_DEFLATED
,
with
closing
(
zipfile
.
ZipFile
(
file_handler
,
'w'
,
zipfile
.
ZIP_DEFLATED
,
allowZip64
=
True
))
as
zip_file
:
allowZip64
=
True
))
as
zip_file
:
def
func
(
f
):
def
func
(
f
):
p
=
pickle
.
Pickler
(
f
,
protocol
=
protocol
)
p
=
pickle
.
Pickler
(
f
,
protocol
=
protocol
)
...
@@ -317,8 +318,8 @@ def load(f, persistent_load=PersistentNdarrayLoad):
...
@@ -317,8 +318,8 @@ def load(f, persistent_load=PersistentNdarrayLoad):
:type persistent_load: callable, optional
:type persistent_load: callable, optional
"""
"""
with
closing
(
zipfile
.
ZipFile
(
f
,
'r
b
'
))
as
zip_file
:
with
closing
(
zipfile
.
ZipFile
(
f
,
'r'
))
as
zip_file
:
p
=
pickle
.
Unpickler
(
String
IO
(
zip_file
.
open
(
'pkl'
)
.
read
()))
p
=
pickle
.
Unpickler
(
Bytes
IO
(
zip_file
.
open
(
'pkl'
)
.
read
()))
p
.
persistent_load
=
persistent_load
(
zip_file
)
p
.
persistent_load
=
persistent_load
(
zip_file
)
return
p
.
load
()
return
p
.
load
()
...
...
theano/misc/tests/test_pkl_utils.py
浏览文件 @
1d7141d1
...
@@ -46,12 +46,12 @@ def test_dump_load_mrg():
...
@@ -46,12 +46,12 @@ def test_dump_load_mrg():
def
test_dump_zip_names
():
def
test_dump_zip_names
():
foo_1
=
theano
.
shared
(
0
,
name
=
'foo'
)
foo_1
=
theano
.
shared
(
0
,
name
=
'foo'
)
foo_2
=
theano
.
shared
(
1
,
name
=
'foo'
)
foo_2
=
theano
.
shared
(
1
,
name
=
'foo'
)
with
open
(
'model.zip'
,
'w'
)
as
f
:
with
open
(
'model.zip'
,
'w
b
'
)
as
f
:
dump
((
foo_1
,
foo_2
,
numpy
.
array
(
2
)),
f
)
dump
((
foo_1
,
foo_2
,
numpy
.
array
(
2
)),
f
)
keys
=
numpy
.
load
(
'model.zip'
)
.
keys
()
keys
=
numpy
.
load
(
'model.zip'
)
.
keys
()
assert
keys
==
[
'foo'
,
'foo_2'
,
'array_0'
,
'pkl'
]
assert
keys
==
[
'foo'
,
'foo_2'
,
'array_0'
,
'pkl'
]
foo
=
numpy
.
load
(
'model.zip'
)[
'foo'
]
foo
=
numpy
.
load
(
'model.zip'
)[
'foo'
]
assert
foo
==
numpy
.
array
(
0
)
assert
foo
==
numpy
.
array
(
0
)
with
open
(
'model.zip'
)
as
f
:
with
open
(
'model.zip'
,
'rb'
)
as
f
:
foo_1
,
foo_2
,
array
=
load
(
f
)
foo_1
,
foo_2
,
array
=
load
(
f
)
assert
array
==
numpy
.
array
(
2
)
assert
array
==
numpy
.
array
(
2
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论