Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
746b85f4
提交
746b85f4
authored
10月 17, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove Python 2.x pickle compatibility class and more stale pickle data tests
上级
af703ed2
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
14 行增加
和
166 行删除
+14
-166
pkl_utils.txt
doc/library/misc/pkl_utils.txt
+0
-4
test_multinomial.py
tests/gpuarray/test_multinomial.py
+3
-2
test_pickle.py
tests/gpuarray/test_pickle.py
+4
-10
test_type.py
tests/gpuarray/test_type.py
+3
-6
test_multinomial.py
tests/sandbox/test_multinomial.py
+0
-40
test_multinomial_wo_replacement.py
tests/sandbox/test_multinomial_wo_replacement.py
+1
-14
pkl_utils.py
theano/misc/pkl_utils.py
+3
-90
没有找到文件。
doc/library/misc/pkl_utils.txt
浏览文件 @
746b85f4
...
...
@@ -15,10 +15,6 @@
.. autoclass:: theano.misc.pkl_utils.StripPickler
.. autoclass:: theano.misc.pkl_utils.CompatUnpickler
.. seealso::
:ref:`tutorial_loadsave`
tests/gpuarray/test_multinomial.py
浏览文件 @
746b85f4
...
...
@@ -7,9 +7,10 @@ import theano
import
tests.unittest_tools
as
utt
from
pickle
import
Unpickler
from
theano
import
config
,
function
,
tensor
from
theano.compat
import
PY3
from
theano.misc.pkl_utils
import
CompatUnpickler
from
theano.sandbox
import
multinomial
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
as
RandomStreams
from
theano.gpuarray.multinomial
import
(
...
...
@@ -384,6 +385,6 @@ def test_unpickle_legacy_op():
if
not
PY3
:
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
"r"
)
as
fp
:
u
=
Compat
Unpickler
(
fp
)
u
=
Unpickler
(
fp
)
m
=
u
.
load
()
assert
isinstance
(
m
,
GPUAChoiceFromUniform
)
tests/gpuarray/test_pickle.py
浏览文件 @
746b85f4
...
...
@@ -13,9 +13,9 @@ import pytest
import
numpy
as
np
from
pickle
import
Unpickler
from
theano
import
config
from
theano.compat
import
PY3
from
theano.misc.pkl_utils
import
CompatUnpickler
from
theano.gpuarray.type
import
ContextNotDefined
...
...
@@ -37,10 +37,7 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag1():
fname
=
"GpuArray.pkl"
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
"rb"
)
as
fp
:
if
PY3
:
u
=
CompatUnpickler
(
fp
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
fp
)
u
=
Unpickler
(
fp
,
encoding
=
"latin1"
)
with
pytest
.
raises
((
ImportError
,
ContextNotDefined
)):
u
.
load
()
finally
:
...
...
@@ -56,10 +53,7 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag2():
fname
=
"GpuArray.pkl"
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
"rb"
)
as
fp
:
if
PY3
:
u
=
CompatUnpickler
(
fp
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
fp
)
u
=
Unpickler
(
fp
,
encoding
=
"latin1"
)
try
:
mat
=
u
.
load
()
except
ImportError
:
...
...
tests/gpuarray/test_type.py
浏览文件 @
746b85f4
...
...
@@ -5,10 +5,10 @@ import theano
pygpu
=
pytest
.
importorskip
(
"pygpu"
)
from
theano.compat
import
PY3
from
pickle
import
Unpickler
from
theano
import
config
from
theano.compile
import
DeepCopyOp
,
Rebroadcast
,
ViewOp
from
theano.misc.pkl_utils
import
CompatUnpickler
from
theano.gpuarray.type
import
GpuArrayType
,
gpuarray_shared_constructor
from
tests.gpuarray.config
import
test_ctx_name
...
...
@@ -122,10 +122,7 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag0():
fname
=
"GpuArray.pkl"
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
"rb"
)
as
fp
:
if
PY3
:
u
=
CompatUnpickler
(
fp
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
fp
)
u
=
Unpickler
(
fp
,
encoding
=
"latin1"
)
mat
=
u
.
load
()
assert
isinstance
(
mat
,
pygpu
.
gpuarray
.
GpuArray
)
assert
np
.
asarray
(
mat
)[
0
]
==
-
42.0
...
...
tests/sandbox/test_multinomial.py
浏览文件 @
746b85f4
import
os
import
sys
import
numpy
as
np
import
theano
import
tests.unittest_tools
as
utt
from
theano
import
config
,
function
,
tensor
from
theano.sandbox
import
multinomial
from
theano.compat
import
PY3
from
theano.misc.pkl_utils
import
CompatUnpickler
def
test_n_samples_1
():
...
...
@@ -51,40 +45,6 @@ def test_n_samples_2():
assert
res
.
sum
()
==
i
def
test_n_samples_compatibility
():
# This test checks if the new change to MultinomialFromUniform is still compatible
# with old interface. Here I will load a graph created (using the old interface) as follows:
# RandomStreams = theano.sandbox.rng_mrg.MRG_RandomStreams
# th_rng = RandomStreams(12345)
# X = T.matrix('X')
# pvals = T.exp(X)
# pvals = pvals / pvals.sum(axis=1, keepdims=True)
# samples = th_rng.multinomial(pvals=pvals)
# pickle.dump([X, samples], open("multinomial_test_graph.pkl", "w"))
folder
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
with
open
(
os
.
path
.
join
(
folder
,
"multinomial_test_graph.pkl"
),
"rb"
)
as
pkl_file
:
if
PY3
:
u
=
CompatUnpickler
(
pkl_file
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
pkl_file
)
try
:
X
,
samples
=
u
.
load
()
except
ImportError
:
# Windows sometimes fail with nonsensical errors like:
# ImportError: No module named type
# ImportError: No module named copy_reg
# when "type" and "copy_reg" are builtin modules.
if
sys
.
platform
==
"win32"
:
exc_type
,
exc_value
,
exc_trace
=
sys
.
exc_info
()
raise
raise
f
=
theano
.
function
([
X
],
samples
)
res
=
f
(
np
.
random
.
randn
(
20
,
10
))
assert
np
.
all
(
res
.
sum
(
axis
=
1
)
==
1
)
def
test_multinomial_0
():
# This tests the MultinomialFromUniform Op directly, not going through the
# multinomial() call in GPU random generation.
...
...
tests/sandbox/test_multinomial_wo_replacement.py
浏览文件 @
746b85f4
import
numpy
as
np
import
pytest
import
os
from
theano
import
config
,
function
,
tensor
from
theano.compat
import
PY3
from
theano.misc.pkl_utils
import
CompatUnpickler
from
theano.sandbox
import
multinomial
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
as
RandomStreams
...
...
@@ -214,14 +212,3 @@ class TestFunction:
avg_pvals
/=
avg_pvals
.
sum
()
avg_diff
=
np
.
mean
(
abs
(
avg_pvals
-
pvals
))
assert
avg_diff
<
mean_rtol
def
test_unpickle_legacy_op
(
self
):
testfile_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
fname
=
"test_sandbox_multinomial_wo_replacement.pkl"
if
not
PY3
:
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
"r"
)
as
fp
:
u
=
CompatUnpickler
(
fp
)
m
=
u
.
load
()
print
(
m
)
assert
isinstance
(
m
,
multinomial
.
ChoiceFromUniform
)
theano/misc/pkl_utils.py
浏览文件 @
746b85f4
...
...
@@ -12,6 +12,9 @@ import sys
import
tempfile
import
zipfile
import
warnings
import
theano
from
collections
import
defaultdict
from
contextlib
import
closing
from
pickle
import
HIGHEST_PROTOCOL
...
...
@@ -22,10 +25,7 @@ try:
except
ImportError
:
DEFAULT_PROTOCOL
=
HIGHEST_PROTOCOL
import
theano
from
theano
import
config
from
theano.compat
import
PY3
from
six
import
string_types
from
theano.compile.sharedvalue
import
SharedVariable
__docformat__
=
"restructuredtext en"
...
...
@@ -80,93 +80,6 @@ class StripPickler(Pickler):
return
Pickler
.
save
(
self
,
obj
)
# Make an unpickler that tries encoding byte streams before raising TypeError.
# This is useful with python 3, in order to unpickle files created with
# python 2.
# This code is taken from Pandas, https://github.com/pydata/pandas,
# under the same 3-clause BSD license.
def
load_reduce
(
self
):
stack
=
self
.
stack
args
=
stack
.
pop
()
func
=
stack
[
-
1
]
try
:
value
=
func
(
*
args
)
except
Exception
:
# try to reencode the arguments
if
self
.
encoding
is
not
None
:
new_args
=
[]
for
arg
in
args
:
if
isinstance
(
arg
,
string_types
):
new_args
.
append
(
arg
.
encode
(
self
.
encoding
))
else
:
new_args
.
append
(
arg
)
args
=
tuple
(
new_args
)
try
:
stack
[
-
1
]
=
func
(
*
args
)
return
except
Exception
:
pass
# if self.is_verbose:
# print(sys.exc_info())
# print(func, args)
raise
stack
[
-
1
]
=
value
if
PY3
:
class
CompatUnpickler
(
pickle
.
_Unpickler
):
"""
Allow to reload in python 3 some pickled numpy ndarray.
.. versionadded:: 0.8
Examples
--------
::
with open(fname, 'rb') as fp:
if PY3:
u = CompatUnpickler(fp, encoding="latin1")
else:
u = CompatUnpickler(fp)
mat = u.load()
"""
pass
# Register `load_reduce` defined above in CompatUnpickler
CompatUnpickler
.
dispatch
[
pickle
.
REDUCE
[
0
]]
=
load_reduce
else
:
class
CompatUnpickler
(
pickle
.
Unpickler
):
"""
Allow to reload in python 3 some pickled numpy ndarray.
.. versionadded:: 0.8
Examples
--------
::
with open(fname, 'rb') as fp:
if PY3:
u = CompatUnpickler(fp, encoding="latin1")
else:
u = CompatUnpickler(fp)
mat = u.load()
"""
pass
class
PersistentNdarrayID
(
object
):
"""Persist ndarrays in an object by saving them to a zip file.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论