Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f36d29fd
提交
f36d29fd
authored
4月 21, 2015
作者:
serdyuk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed CudaNdarray pickling/unpickling
上级
88c7752a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
4 行删除
+50
-4
pkl_utils.py
theano/misc/pkl_utils.py
+30
-4
test_pkl_utils.py
theano/misc/tests/test_pkl_utils.py
+20
-0
没有找到文件。
theano/misc/pkl_utils.py
浏览文件 @
f36d29fd
...
@@ -6,22 +6,29 @@ unit tests or regression tests.
...
@@ -6,22 +6,29 @@ unit tests or regression tests.
"""
"""
import
numpy
import
numpy
import
pickle
import
pickle
from
six
import
StringIO
import
sys
import
sys
import
tempfile
import
tempfile
import
zipfile
import
zipfile
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
six
import
StringIO
try
:
try
:
from
pickle
import
DEFAULT_PROTOCOL
from
pickle
import
DEFAULT_PROTOCOL
except
ImportError
:
except
ImportError
:
DEFAULT_PROTOCOL
=
HIGHEST_PROTOCOL
DEFAULT_PROTOCOL
=
HIGHEST_PROTOCOL
import
theano
import
theano
from
theano
import
config
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano.compat.six
import
string_types
from
theano.compat.six
import
string_types
from
theano.compile.sharedvalue
import
SharedVariable
from
theano.compile.sharedvalue
import
SharedVariable
try
:
from
cuda_ndarray
import
cuda_ndarray
except
ImportError
:
cuda_ndarray
=
None
__docformat__
=
"restructuredtext en"
__docformat__
=
"restructuredtext en"
...
@@ -137,12 +144,16 @@ class PersistentNdarrayID(object):
...
@@ -137,12 +144,16 @@ class PersistentNdarrayID(object):
return
name
return
name
def
__call__
(
self
,
obj
):
def
__call__
(
self
,
obj
):
if
type
(
obj
)
is
numpy
.
ndarray
:
if
((
type
(
obj
)
is
numpy
.
ndarray
)
or
(
type
(
obj
)
is
cuda_ndarray
.
CudaNdarray
)):
if
id
(
obj
)
not
in
self
.
seen
:
if
id
(
obj
)
not
in
self
.
seen
:
def
write_array
(
f
):
def
write_array
(
f
):
numpy
.
lib
.
format
.
write_array
(
f
,
obj
)
numpy
.
lib
.
format
.
write_array
(
f
,
numpy
.
asarray
(
obj
)
)
name
=
self
.
_resolve_name
(
obj
)
name
=
self
.
_resolve_name
(
obj
)
zipadd
(
write_array
,
self
.
zip_file
,
name
)
zipadd
(
write_array
,
self
.
zip_file
,
name
)
if
type
(
obj
)
is
cuda_ndarray
.
CudaNdarray
:
self
.
seen
[
id
(
obj
)]
=
'cuda_ndarray.{}'
.
format
(
name
)
else
:
self
.
seen
[
id
(
obj
)]
=
'ndarray.{}'
.
format
(
name
)
self
.
seen
[
id
(
obj
)]
=
'ndarray.{}'
.
format
(
name
)
return
self
.
seen
[
id
(
obj
)]
return
self
.
seen
[
id
(
obj
)]
...
@@ -218,7 +229,22 @@ class PersistentNdarrayLoad(object):
...
@@ -218,7 +229,22 @@ class PersistentNdarrayLoad(object):
def
__call__
(
self
,
persid
):
def
__call__
(
self
,
persid
):
array_type
,
name
=
persid
.
split
(
'.'
)
array_type
,
name
=
persid
.
split
(
'.'
)
return
numpy
.
lib
.
format
.
read_array
(
self
.
zip_file
.
open
(
name
))
array
=
numpy
.
lib
.
format
.
read_array
(
self
.
zip_file
.
open
(
name
))
if
array_type
==
'cuda_ndarray'
:
if
config
.
experimental
.
unpickle_gpu_on_cpu
:
# directly return numpy array
warnings
.
warn
(
"config.experimental.unpickle_gpu_on_cpu is set "
"to True. Unpickling CudaNdarray as "
"numpy.ndarray"
)
return
array
elif
cuda_ndarray
:
return
cuda_ndarray
.
CudaNdarray
(
array
)
else
:
raise
ImportError
(
"Cuda not found. Cannot unpickle "
"CudaNdarray"
)
else
:
return
array
def
dump
(
obj
,
f
,
protocol
=
DEFAULT_PROTOCOL
,
def
dump
(
obj
,
f
,
protocol
=
DEFAULT_PROTOCOL
,
...
...
theano/misc/tests/test_pkl_utils.py
0 → 100644
浏览文件 @
f36d29fd
from
numpy.testing
import
assert_allclose
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.var
import
CudaNdarraySharedVariable
from
theano.misc.pkl_utils
import
dump
,
load
def
test_dump_load
():
x
=
CudaNdarraySharedVariable
(
'x'
,
CudaNdarrayType
((
1
,
1
),
name
=
'x'
),
[[
1
]],
False
)
with
open
(
'test'
,
'w'
)
as
f
:
dump
(
x
,
f
)
with
open
(
'test'
,
'r'
)
as
f
:
x
=
load
(
f
)
assert
x
.
name
==
'x'
assert_allclose
(
x
.
get_value
(),
[[
1
]])
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论