Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
030c7b96
提交
030c7b96
authored
5月 03, 2015
作者:
David Warde-Farley
提交者:
Arnaud Bergeron
6月 22, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Import rewrites and renames to 3.x names.
Import moved modules from theano.compat.six.moves. Use six.moves.StringIO rather than already available io.StringIO.
上级
c9498586
隐藏空白字符变更
内嵌
并排
正在显示
36 个修改的文件
包含
152 行增加
和
149 行删除
+152
-149
debugmode.py
theano/compile/debugmode.py
+2
-2
function.py
theano/compile/function.py
+4
-2
function_module.py
theano/compile/function_module.py
+6
-6
ops.py
theano/compile/ops.py
+3
-3
test_function.py
theano/compile/tests/test_function.py
+2
-2
test_function_module.py
theano/compile/tests/test_function_module.py
+10
-10
test_profiling.py
theano/compile/tests/test_profiling.py
+2
-3
callcache.py
theano/gof/callcache.py
+3
-3
cmodule.py
theano/gof/cmodule.py
+8
-8
compiledir.py
theano/gof/compiledir.py
+3
-3
fg.py
theano/gof/fg.py
+2
-2
link.py
theano/gof/link.py
+4
-3
op.py
theano/gof/op.py
+2
-2
test_graph_opt_caching.py
theano/gof/tests/test_graph_opt_caching.py
+1
-1
gradient.py
theano/gradient.py
+6
-6
check_duplicate_key.py
theano/misc/check_duplicate_key.py
+3
-3
test_bench_loopfusion.py
theano/sandbox/cuda/tests/test_bench_loopfusion.py
+1
-1
test_type.py
theano/sandbox/cuda/tests/test_type.py
+5
-2
type.py
theano/sandbox/cuda/type.py
+3
-3
elemwise.py
theano/sandbox/gpuarray/elemwise.py
+1
-2
subtensor.py
theano/sandbox/gpuarray/subtensor.py
+2
-2
neighbourhoods.py
theano/sandbox/neighbourhoods.py
+2
-2
test_scan.py
theano/sandbox/scan_module/tests/test_scan.py
+1
-1
test_utils.py
theano/sandbox/scan_module/tests/test_utils.py
+1
-1
test_scan.py
theano/scan_module/tests/test_scan.py
+3
-3
downsample.py
theano/tensor/signal/downsample.py
+23
-23
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+9
-9
test_basic.py
theano/tensor/tests/test_basic.py
+3
-3
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+4
-4
test_gc.py
theano/tensor/tests/test_gc.py
+8
-8
test_type_other.py
theano/tensor/tests/test_type_other.py
+2
-2
run_tests_in_batch.py
theano/tests/run_tests_in_batch.py
+3
-3
test_pickle_unpickle_theano_fn.py
theano/tests/test_pickle_unpickle_theano_fn.py
+5
-5
test_record.py
theano/tests/test_record.py
+9
-10
test_tutorial.py
theano/tests/test_tutorial.py
+5
-5
unittest_tools.py
theano/tests/unittest_tools.py
+1
-1
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
030c7b96
...
...
@@ -7,9 +7,9 @@ from __future__ import print_function
import
copy
import
sys
import
copy_reg
import
gc
import
logging
import
theano.compat.six.moves.copyreg
as
copyreg
from
itertools
import
izip
,
product
as
itertools_product
import
numpy
...
...
@@ -2503,7 +2503,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
def
_pickle_DebugMode_Maker
(
maker
):
raise
NotImplementedError
(
'DebugMode is not picklable (yet)'
)
copy
_
reg
.
pickle
(
_Maker
,
_pickle_DebugMode_Maker
)
copyreg
.
pickle
(
_Maker
,
_pickle_DebugMode_Maker
)
########################
#
...
...
theano/compile/function.py
浏览文件 @
030c7b96
"""Define the `function` function
"""
import
cPickle
__docformat__
=
"restructuredtext en"
import
theano.compat.six.moves.cPickle
as
pickle
import
logging
import
traceback
as
tb
...
...
@@ -49,7 +51,7 @@ def function_dump(filename, inputs, outputs=None, mode=None, updates=None,
allow_input_downcast
=
allow_input_downcast
,
profile
=
profile
,
on_unused_input
=
on_unused_input
)
with
open
(
filename
,
'wb'
)
as
f
:
cP
ickle
.
dump
(
d
,
f
,
-
1
)
p
ickle
.
dump
(
d
,
f
,
-
1
)
def
function
(
inputs
,
outputs
=
None
,
mode
=
None
,
updates
=
None
,
givens
=
None
,
...
...
theano/compile/function_module.py
浏览文件 @
030c7b96
...
...
@@ -3,8 +3,8 @@
from
__future__
import
print_function
import
copy
import
copy_
reg
import
cP
ickle
import
theano.compat.six.moves.copyreg
as
copy
reg
import
theano.compat.six.moves.cPickle
as
p
ickle
import
itertools
import
time
import
warnings
...
...
@@ -776,7 +776,7 @@ def _constructor_Function(maker, input_storage, inputs_data):
(
container
.
data
==
x
)
return
f
copy
_
reg
.
pickle
(
Function
,
_pickle_Function
)
copyreg
.
pickle
(
Function
,
_pickle_Function
)
###
...
...
@@ -957,7 +957,7 @@ class FunctionMaker(object):
# finish. Should be changed in definitive version.
tmp
=
theano
.
config
.
unpickle_function
theano
.
config
.
unpickle_function
=
False
graph_db
=
cP
ickle
.
load
(
f
)
graph_db
=
p
ickle
.
load
(
f
)
# hack end
f
.
close
()
...
...
@@ -1090,7 +1090,7 @@ class FunctionMaker(object):
optimizer_profile
=
optimizer
(
self
.
fgraph
)
graph_db
.
update
({
before_opt
:
self
.
fgraph
})
f
=
open
(
graph_db_file
,
'wb'
)
cP
ickle
.
dump
(
graph_db
,
f
,
-
1
)
p
ickle
.
dump
(
graph_db
,
f
,
-
1
)
f
.
close
()
print
(
'new graph saved into graph_db'
)
release_lock
()
...
...
@@ -1428,7 +1428,7 @@ def _constructor_FunctionMaker(kwargs):
else
:
return
None
copy
_
reg
.
pickle
(
FunctionMaker
,
_pickle_FunctionMaker
)
copyreg
.
pickle
(
FunctionMaker
,
_pickle_FunctionMaker
)
__checkers
=
[]
...
...
theano/compile/ops.py
浏览文件 @
030c7b96
...
...
@@ -4,7 +4,7 @@ and Ops building class (:class:`FromFunctionOp`) and decorator
"""
import
copy
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
warnings
import
theano
...
...
@@ -517,12 +517,12 @@ class FromFunctionOp(gof.Op):
try
:
obj
=
load_back
(
mod
,
name
)
except
(
ImportError
,
KeyError
,
AttributeError
):
raise
cP
ickle
.
PicklingError
(
raise
p
ickle
.
PicklingError
(
"Can't pickle as_op(), not found as
%
s.
%
s"
%
(
mod
,
name
))
else
:
if
obj
is
not
self
:
raise
cP
ickle
.
PicklingError
(
raise
p
ickle
.
PicklingError
(
"Can't pickle as_op(), not the object "
"at
%
s.
%
s"
%
(
mod
,
name
))
return
load_back
,
(
mod
,
name
)
...
...
theano/compile/tests/test_function.py
浏览文件 @
030c7b96
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
os
import
shutil
import
tempfile
...
...
@@ -17,7 +17,7 @@ def test_function_dump():
fname
=
os
.
path
.
join
(
tmpdir
,
'test_function_dump.pkl'
)
theano
.
function_dump
(
fname
,
[
v
],
v
+
1
)
f
=
open
(
fname
,
'rb'
)
l
=
cP
ickle
.
load
(
f
)
l
=
p
ickle
.
load
(
f
)
f
.
close
()
finally
:
if
tmpdir
is
not
None
:
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
030c7b96
import
copy
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
numpy
import
unittest
...
...
@@ -406,7 +406,7 @@ class T_function(unittest.TestCase):
func
=
function
([
x
],
x
+
1
)
func
.
fn
.
allow_gc
=
False
func
([
1
])
check_list
=
[]
for
key
,
val
in
func
.
fn
.
storage_map
.
iteritems
():
if
not
isinstance
(
key
,
theano
.
gof
.
Constant
):
...
...
@@ -496,8 +496,8 @@ class T_picklefunction(unittest.TestCase):
try
:
# Note that here we also test protocol 0 on purpose, since it
# should work (even though one should not use it).
g
=
cPickle
.
loads
(
cP
ickle
.
dumps
(
f
,
protocol
=
0
))
g
=
cPickle
.
loads
(
cP
ickle
.
dumps
(
f
,
protocol
=-
1
))
g
=
pickle
.
loads
(
p
ickle
.
dumps
(
f
,
protocol
=
0
))
g
=
pickle
.
loads
(
p
ickle
.
dumps
(
f
,
protocol
=-
1
))
except
NotImplementedError
as
e
:
if
e
[
0
]
.
startswith
(
'DebugMode is not picklable'
):
return
...
...
@@ -535,11 +535,11 @@ class T_picklefunction(unittest.TestCase):
old_default_link
=
config
.
linker
try
:
try
:
str_f
=
cP
ickle
.
dumps
(
f
,
protocol
=-
1
)
str_f
=
p
ickle
.
dumps
(
f
,
protocol
=-
1
)
config
.
mode
=
'Mode'
config
.
linker
=
'py'
config
.
optimizer
=
'None'
g
=
cP
ickle
.
loads
(
str_f
)
g
=
p
ickle
.
loads
(
str_f
)
# print g.maker.mode
# print compile.mode.default_mode
except
NotImplementedError
as
e
:
...
...
@@ -593,8 +593,8 @@ class T_picklefunction(unittest.TestCase):
# try to pickle the entire things
try
:
saved_format
=
cP
ickle
.
dumps
(
list_of_things
,
protocol
=-
1
)
new_list_of_things
=
cP
ickle
.
loads
(
saved_format
)
saved_format
=
p
ickle
.
dumps
(
list_of_things
,
protocol
=-
1
)
new_list_of_things
=
p
ickle
.
loads
(
saved_format
)
except
NotImplementedError
as
e
:
if
e
[
0
]
.
startswith
(
'DebugMode is not picklable'
):
return
...
...
@@ -657,7 +657,7 @@ class T_picklefunction(unittest.TestCase):
from
theano.compat
import
BytesIO
fp
=
BytesIO
()
p
=
cP
ickle
.
Pickler
(
fp
,
2
)
p
=
p
ickle
.
Pickler
(
fp
,
2
)
p
.
persistent_id
=
pers_save
try
:
p
.
dump
(
f
)
...
...
@@ -668,7 +668,7 @@ class T_picklefunction(unittest.TestCase):
raise
fp2
=
BytesIO
(
fp
.
getvalue
())
fp
.
close
()
p
=
cP
ickle
.
Unpickler
(
fp2
)
p
=
p
ickle
.
Unpickler
(
fp2
)
p
.
persistent_load
=
pers_load
f2
=
p
.
load
()
fp2
.
close
()
...
...
theano/compile/tests/test_profiling.py
浏览文件 @
030c7b96
...
...
@@ -4,11 +4,10 @@ Test of memory profiling
"""
import
unittest
import
StringIO
import
numpy
import
theano
from
theano.compat.six.moves
import
StringIO
import
theano.tensor
as
T
from
theano.ifelse
import
ifelse
...
...
@@ -47,7 +46,7 @@ class Test_profiling(unittest.TestCase):
inp
=
[
numpy
.
arange
(
1024
,
dtype
=
'float32'
)
+
1
for
i
in
range
(
len
(
x
))]
output
=
f
(
*
inp
)
buf
=
StringIO
.
StringIO
()
buf
=
StringIO
()
f
.
profile
.
summary
(
buf
)
# regression testing for future algo speed up
...
...
theano/gof/callcache.py
浏览文件 @
030c7b96
import
cPickle
import
logging
import
theano.compat.six.moves.cPickle
as
pickle
_logger
=
logging
.
getLogger
(
"theano.gof.callcache"
)
...
...
@@ -11,7 +11,7 @@ class CallCache(object):
if
filename
is
None
:
raise
IOError
(
'bad filename'
)
# just goes to except
f
=
open
(
filename
,
'r'
)
self
.
cache
=
cP
ickle
.
load
(
f
)
self
.
cache
=
p
ickle
.
load
(
f
)
f
.
close
()
except
IOError
:
self
.
cache
=
{}
...
...
@@ -20,7 +20,7 @@ class CallCache(object):
if
filename
is
None
:
filename
=
self
.
filename
f
=
open
(
filename
,
'w'
)
cP
ickle
.
dump
(
self
.
cache
,
f
)
p
ickle
.
dump
(
self
.
cache
,
f
)
f
.
close
()
def
call
(
self
,
fn
,
args
=
(),
key
=
None
):
...
...
theano/gof/cmodule.py
浏览文件 @
030c7b96
...
...
@@ -2,7 +2,7 @@
"""
from
__future__
import
print_function
import
atexit
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
logging
import
os
import
re
...
...
@@ -481,8 +481,8 @@ class KeyData(object):
# Note that writing in binary mode is important under Windows.
try
:
with
open
(
self
.
key_pkl
,
'wb'
)
as
f
:
cPickle
.
dump
(
self
,
f
,
protocol
=
cP
ickle
.
HIGHEST_PROTOCOL
)
except
cP
ickle
.
PicklingError
:
pickle
.
dump
(
self
,
f
,
protocol
=
p
ickle
.
HIGHEST_PROTOCOL
)
except
p
ickle
.
PicklingError
:
_logger
.
warning
(
"Cache leak due to unpickle-able key data
%
s"
,
self
.
keys
)
os
.
remove
(
self
.
key_pkl
)
...
...
@@ -721,7 +721,7 @@ class ModuleCache(object):
try
:
with
open
(
key_pkl
,
'rb'
)
as
f
:
key_data
=
cP
ickle
.
load
(
f
)
key_data
=
p
ickle
.
load
(
f
)
except
EOFError
:
# Happened once... not sure why (would be worth
# investigating if it ever happens again).
...
...
@@ -957,7 +957,7 @@ class ModuleCache(object):
try
:
key_data
.
add_key
(
key
,
save_pkl
=
bool
(
key
[
0
]))
key_broken
=
False
except
cP
ickle
.
PicklingError
:
except
p
ickle
.
PicklingError
:
key_data
.
remove_key
(
key
)
key_broken
=
True
# We need the lock while we check in case of parallel
...
...
@@ -1011,7 +1011,7 @@ class ModuleCache(object):
if
key
[
0
]:
try
:
key_data
.
save_pkl
()
except
cP
ickle
.
PicklingError
:
except
p
ickle
.
PicklingError
:
key_broken
=
True
key_data
.
remove_key
(
key
)
key_data
.
save_pkl
()
...
...
@@ -1129,7 +1129,7 @@ class ModuleCache(object):
for
i
in
range
(
3
):
try
:
with
open
(
key_pkl
,
'rb'
)
as
f
:
key_data
=
cP
ickle
.
load
(
f
)
key_data
=
p
ickle
.
load
(
f
)
break
except
EOFError
:
# This file is probably getting written/updated at the
...
...
@@ -1138,7 +1138,7 @@ class ModuleCache(object):
if
i
==
2
:
with
compilelock
.
lock_ctx
():
with
open
(
key_pkl
,
'rb'
)
as
f
:
key_data
=
cP
ickle
.
load
(
f
)
key_data
=
p
ickle
.
load
(
f
)
time
.
sleep
(
2
)
found
=
sum
(
key
==
other_key
for
other_key
in
key_data
.
keys
)
...
...
theano/gof/compiledir.py
浏览文件 @
030c7b96
from
__future__
import
print_function
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
errno
import
logging
import
os
...
...
@@ -280,7 +280,7 @@ def cleanup():
file
=
open
(
filename
,
'rb'
)
# print file
try
:
keydata
=
cP
ickle
.
load
(
file
)
keydata
=
p
ickle
.
load
(
file
)
for
key
in
list
(
keydata
.
keys
):
have_npy_abi_version
=
False
have_c_compiler
=
False
...
...
@@ -352,7 +352,7 @@ def print_compiledir_content():
try
:
filename
=
os
.
path
.
join
(
compiledir
,
dir
,
"key.pkl"
)
file
=
open
(
filename
,
'rb'
)
keydata
=
cP
ickle
.
load
(
file
)
keydata
=
p
ickle
.
load
(
file
)
ops
=
list
(
set
([
x
for
x
in
flatten
(
keydata
.
keys
)
if
isinstance
(
x
,
theano
.
gof
.
Op
)]))
if
len
(
ops
)
==
0
:
...
...
theano/gof/fg.py
浏览文件 @
030c7b96
...
...
@@ -4,7 +4,6 @@ Contains the FunctionGraph class and exception
types that it can raise
"""
from
__future__
import
print_function
import
StringIO
import
sys
import
time
import
traceback
...
...
@@ -17,6 +16,7 @@ from theano import config
import
warnings
from
theano.compat
import
OrderedDict
from
theano.compat.six.moves
import
StringIO
from
theano.misc.ordered_set
import
OrderedSet
NullType
=
None
...
...
@@ -334,7 +334,7 @@ class FunctionGraph(utils.object2):
tr
=
getattr
(
r
.
tag
,
'trace'
,
None
)
detailed_err_msg
=
""
if
tr
:
sio
=
StringIO
.
StringIO
()
sio
=
StringIO
()
traceback
.
print_list
(
tr
,
sio
)
tr
=
sio
.
getvalue
()
detailed_err_msg
+=
"
\n
Backtrace when the variable is created:
\n
"
...
...
theano/gof/link.py
浏览文件 @
030c7b96
...
...
@@ -2,12 +2,12 @@
from
__future__
import
print_function
from
copy
import
copy
,
deepcopy
from
sys
import
getsizeof
import
StringIO
import
sys
import
traceback
import
numpy
import
theano
from
theano.compat.six.moves
import
StringIO
from
theano.gof
import
utils
from
theano.gof
import
graph
from
theano.gof.type
import
Type
...
...
@@ -157,8 +157,9 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
# Print node backtrace
tr
=
getattr
(
node
.
outputs
[
0
]
.
tag
,
'trace'
,
None
)
if
tr
:
sio
=
StringIO
.
StringIO
()
sio
=
StringIO
()
traceback
.
print_list
(
tr
,
sio
)
traceback
.
print_list
(
tr
.
decode
(
'ascii'
),
sio
)
tr
=
sio
.
getvalue
()
detailed_err_msg
+=
"
\n
Backtrace when the node is created:
\n
"
detailed_err_msg
+=
str
(
tr
)
...
...
@@ -172,7 +173,7 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
if
theano
.
config
.
exception_verbosity
==
'high'
:
f
=
StringIO
.
StringIO
()
f
=
StringIO
()
theano
.
printing
.
debugprint
(
node
,
file
=
f
,
stop_on_name
=
True
,
print_type
=
True
)
detailed_err_msg
+=
"
\n
Debugprint of the apply node:
\n
"
...
...
theano/gof/op.py
浏览文件 @
030c7b96
...
...
@@ -17,7 +17,6 @@ import logging
import
numpy
import
os
import
re
import
StringIO
import
sys
import
traceback
import
warnings
...
...
@@ -26,6 +25,7 @@ import theano
from
theano
import
config
import
theano.gof.cc
from
theano.compat.six.moves
import
StringIO
from
theano.gof
import
graph
from
theano.gof
import
utils
from
theano.gof.cmodule
import
GCC_compiler
...
...
@@ -459,7 +459,7 @@ class PureOp(object):
" have the requested type.
\n
"
)
tr
=
getattr
(
v
.
tag
,
'trace'
,
None
)
if
tr
:
sio
=
StringIO
.
StringIO
()
sio
=
StringIO
()
traceback
.
print_list
(
tr
,
sio
)
tr
=
sio
.
getvalue
()
detailed_err_msg
+=
(
...
...
theano/gof/tests/test_graph_opt_caching.py
浏览文件 @
030c7b96
import
unittest
,
os
import
numpy
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
from
theano.compat
import
DictMixin
,
OrderedDict
import
theano
import
theano.tensor
as
T
...
...
theano/gradient.py
浏览文件 @
030c7b96
"""Driver for gradient calculations."""
from
__future__
import
print_function
import
__builtin__
import
theano.compat.six.moves.builtins
as
builtins
from
itertools
import
izip
import
logging
import
time
...
...
@@ -1387,9 +1387,9 @@ class numeric_grad(object):
# if not dtypes == [dtypes[0]] * len(apt):
# raise TypeError('All function arguments must have same dtype')
total_size
=
__builtin__
.
sum
(
prod
(
sh
)
for
sh
in
shapes
)
total_size
=
builtins
.
sum
(
prod
(
sh
)
for
sh
in
shapes
)
working_dtype
=
__builtin__
.
min
(
working_dtype
=
builtins
.
min
(
(
self
.
type_eps
[
dt
],
dt
)
for
dt
in
dtypes
)[
1
]
# create un-initialized memory
...
...
@@ -1401,7 +1401,7 @@ class numeric_grad(object):
gx
=
numpy
.
ndarray
((
total_size
,),
dtype
=
working_dtype
)
if
eps
is
None
:
eps
=
__builtin__
.
max
(
self
.
type_eps
[
dt
]
for
dt
in
dtypes
)
eps
=
builtins
.
max
(
self
.
type_eps
[
dt
]
for
dt
in
dtypes
)
# set up aliases so that apt[i] is backed by memory in x
# and self.gf is backed by memory in gx
...
...
@@ -1586,9 +1586,9 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None,
float64
=
1e-4
)
if
abs_tol
is
None
:
abs_tol
=
__builtin__
.
max
(
_type_tol
[
str
(
p
.
dtype
)]
for
p
in
pt
)
abs_tol
=
builtins
.
max
(
_type_tol
[
str
(
p
.
dtype
)]
for
p
in
pt
)
if
rel_tol
is
None
:
rel_tol
=
__builtin__
.
max
(
_type_tol
[
str
(
p
.
dtype
)]
for
p
in
pt
)
rel_tol
=
builtins
.
max
(
_type_tol
[
str
(
p
.
dtype
)]
for
p
in
pt
)
if
rng
is
None
:
raise
TypeError
((
'rng should be a valid instance of '
...
...
theano/misc/check_duplicate_key.py
浏览文件 @
030c7b96
from
__future__
import
print_function
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
os
,
sys
import
theano
...
...
@@ -48,7 +48,7 @@ for dir in dirs:
if
DISPLAY_DUPLICATE_KEYS
:
for
k
,
v
in
keys
.
iteritems
():
if
v
>
1
:
print
(
"Duplicate key (
%
i copies):
%
s"
%
(
v
,
cP
ickle
.
loads
(
k
)))
print
(
"Duplicate key (
%
i copies):
%
s"
%
(
v
,
p
ickle
.
loads
(
k
)))
nbs_keys
=
{}
# nb seen -> now many key
for
val
in
keys
.
values
():
...
...
@@ -70,7 +70,7 @@ if DISPLAY_MOST_FREQUENT_DUPLICATE_CCODE:
m
=
max
(
nbs_mod
.
keys
())
print
(
"The keys associated to the mod.{cpp,cu} with the most number of copy:"
)
for
kk
in
nbs_mod_to_key
[
m
]:
kk
=
cP
ickle
.
loads
(
kk
)
kk
=
p
ickle
.
loads
(
kk
)
print
(
kk
)
print
(
"key.pkl histograph"
)
...
...
theano/sandbox/cuda/tests/test_bench_loopfusion.py
浏览文件 @
030c7b96
...
...
@@ -10,7 +10,7 @@ from __future__ import print_function
# so state is ignored
# since this job is not restartable, channel is also ignored
import
logging
,
StringIO
,
time
,
sys
import
logging
,
io
,
time
,
sys
import
numpy
...
...
theano/sandbox/cuda/tests/test_type.py
浏览文件 @
030c7b96
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
os.path
import
sys
...
...
@@ -44,7 +44,6 @@ def test_unpickle_cudandarray_as_numpy_ndarray_flag0():
assert
numpy
.
asarray
(
mat
)[
0
]
==
-
42.0
else
:
assert_raises
(
ImportError
,
u
.
load
)
finally
:
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
...
...
@@ -58,11 +57,15 @@ def test_unpickle_cudandarray_as_numpy_ndarray_flag1():
fname
=
'CudaNdarray.pkl'
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
'rb'
)
as
fp
:
<<<<<<<
HEAD
if
PY3
:
u
=
CompatUnpickler
(
fp
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
fp
)
mat
=
u
.
load
()
=======
mat
=
pickle
.
load
(
fp
)
>>>>>>>
Import
rewrites
and
renames
to
3.
x
names
.
assert
isinstance
(
mat
,
numpy
.
ndarray
)
assert
mat
[
0
]
==
-
42.0
...
...
theano/sandbox/cuda/type.py
浏览文件 @
030c7b96
...
...
@@ -2,7 +2,7 @@
"""
from
__future__
import
print_function
import
os
import
copy_
reg
import
theano.compat.six.moves.copyreg
as
copy
reg
import
warnings
import
numpy
...
...
@@ -546,7 +546,7 @@ def CudaNdarray_unpickler(npa):
else
:
raise
ImportError
(
"Cuda not found. Cannot unpickle CudaNdarray"
)
copy
_
reg
.
constructor
(
CudaNdarray_unpickler
)
copyreg
.
constructor
(
CudaNdarray_unpickler
)
def
CudaNdarray_pickler
(
cnda
):
...
...
@@ -554,5 +554,5 @@ def CudaNdarray_pickler(cnda):
# In case cuda is not imported.
if
cuda
is
not
None
:
copy
_
reg
.
pickle
(
cuda
.
CudaNdarray
,
CudaNdarray_pickler
,
copyreg
.
pickle
(
cuda
.
CudaNdarray
,
CudaNdarray_pickler
,
CudaNdarray_unpickler
)
theano/sandbox/gpuarray/elemwise.py
浏览文件 @
030c7b96
from
__future__
import
print_function
import
copy
from
itertools
import
izip
from
StringIO
import
StringIO
import
numpy
import
theano
from
theano
import
Apply
,
scalar
,
config
from
theano
import
scalar
as
scal
from
theano.compat.six.moves
import
StringIO
from
theano.gof.utils
import
MethodNotDefined
from
theano.scalar
import
Scalar
from
theano.tensor.elemwise
import
(
Elemwise
,
DimShuffle
,
CAReduceDtype
)
...
...
theano/sandbox/gpuarray/subtensor.py
浏览文件 @
030c7b96
from
__future__
import
print_function
import
copy
import
StringIO
import
numpy
import
theano
from
theano
import
tensor
,
gof
,
Op
from
theano.compat.six.moves
import
StringIO
from
theano.tensor.subtensor
import
IncSubtensor
,
Subtensor
,
get_idx_list
import
theano.tensor.inplace
...
...
@@ -91,7 +91,7 @@ class GpuSubtensor(HideC, Subtensor):
if (!
%(out)
s) {
%(fail)
s }
"""
%
dict
(
out
=
outputs
[
0
],
inp
=
inp
,
fail
=
sub
[
'fail'
])
sio
=
StringIO
.
StringIO
()
sio
=
StringIO
()
print
(
"""
ssize_t starts[
%(sz)
s];
ssize_t stops[
%(sz)
s];
...
...
theano/sandbox/neighbourhoods.py
浏览文件 @
030c7b96
...
...
@@ -12,7 +12,7 @@ import theano
from
theano
import
gof
,
Op
,
tensor
,
Variable
,
Apply
import
numpy
import
__builtin__
import
theano.compat.six.moves.builtins
as
builtins
class
NeighbourhoodsFromImages
(
Op
):
...
...
@@ -216,7 +216,7 @@ class NeighbourhoodsFromImages(Op):
for
i
in
xrange
(
len
(
self
.
strides
)):
code
+=
self
.
_py_innerloop
(
i
)
code
+=
self
.
_py_assignment
()
return
code
,
__builtin__
.
compile
(
code
,
'<string>'
,
'exec'
)
return
code
,
builtins
.
compile
(
code
,
'<string>'
,
'exec'
)
def
_py_outerloops
(
self
):
code_before
=
""
...
...
theano/sandbox/scan_module/tests/test_scan.py
浏览文件 @
030c7b96
...
...
@@ -6,7 +6,7 @@ import time
import
sys
import
unittest
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
numpy
from
numpy.testing
import
dec
...
...
theano/sandbox/scan_module/tests/test_utils.py
浏览文件 @
030c7b96
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
numpy
import
unittest
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
030c7b96
...
...
@@ -7,7 +7,7 @@ import time
import
unittest
import
copy
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
numpy
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
...
...
@@ -248,12 +248,12 @@ class T_Scan(unittest.TestCase):
f_out
=
open
(
'tmp_scan_test_pickle.pkl'
,
'wb'
)
try
:
cP
ickle
.
dump
(
_my_f
,
f_out
,
protocol
=-
1
)
p
ickle
.
dump
(
_my_f
,
f_out
,
protocol
=-
1
)
finally
:
f_out
.
close
()
f_in
=
open
(
'tmp_scan_test_pickle.pkl'
,
'rb'
)
try
:
my_f
=
cP
ickle
.
load
(
f_in
)
my_f
=
p
ickle
.
load
(
f_in
)
finally
:
f_in
.
close
()
finally
:
...
...
theano/tensor/signal/downsample.py
浏览文件 @
030c7b96
...
...
@@ -6,7 +6,7 @@ DownsampleFactorMax, DownsampleAvg, DownsampleSoftmax.
"""
from
__future__
import
print_function
# This file should move along with conv.py
import
__builtin__
import
theano.compat.six.moves.builtins
as
builtins
import
numpy
...
...
@@ -286,16 +286,16 @@ class DownsampleFactorMax(Op):
for
k
in
xrange
(
x
.
shape
[
1
]):
for
r
in
xrange
(
pr
):
row_st
=
r
*
st0
row_end
=
__builtin__
.
min
(
row_st
+
ds0
,
img_rows
)
row_end
=
builtins
.
min
(
row_st
+
ds0
,
img_rows
)
if
not
inc_pad
:
row_st
=
__builtin__
.
max
(
row_st
,
self
.
padding
[
0
])
row_end
=
__builtin__
.
min
(
row_end
,
x
.
shape
[
-
2
]
+
pad_h
)
row_st
=
builtins
.
max
(
row_st
,
self
.
padding
[
0
])
row_end
=
builtins
.
min
(
row_end
,
x
.
shape
[
-
2
]
+
pad_h
)
for
c
in
xrange
(
pc
):
col_st
=
c
*
st1
col_end
=
__builtin__
.
min
(
col_st
+
ds1
,
img_cols
)
col_end
=
builtins
.
min
(
col_st
+
ds1
,
img_cols
)
if
not
inc_pad
:
col_st
=
__builtin__
.
max
(
col_st
,
self
.
padding
[
1
])
col_end
=
__builtin__
.
min
(
col_end
,
col_st
=
builtins
.
max
(
col_st
,
self
.
padding
[
1
])
col_end
=
builtins
.
min
(
col_end
,
x
.
shape
[
-
1
]
+
pad_w
)
zz
[
n
,
k
,
r
,
c
]
=
func
(
y
[
n
,
k
,
row_st
:
row_end
,
col_st
:
col_end
])
...
...
@@ -560,11 +560,11 @@ class DownsampleFactorMaxGrad(Op):
for
n
in
xrange
(
x
.
shape
[
0
]):
for
k
in
xrange
(
x
.
shape
[
1
]):
for
r
in
xrange
(
pr
):
row_st
=
__builtin__
.
max
(
r
*
st0
,
self
.
padding
[
0
])
row_end
=
__builtin__
.
min
(
row_st
+
ds0
,
img_rows
)
row_st
=
builtins
.
max
(
r
*
st0
,
self
.
padding
[
0
])
row_end
=
builtins
.
min
(
row_st
+
ds0
,
img_rows
)
for
c
in
xrange
(
pc
):
col_st
=
__builtin__
.
max
(
c
*
st1
,
self
.
padding
[
1
])
col_end
=
__builtin__
.
min
(
col_st
+
ds1
,
img_cols
)
col_st
=
builtins
.
max
(
c
*
st1
,
self
.
padding
[
1
])
col_end
=
builtins
.
min
(
col_st
+
ds1
,
img_cols
)
for
row_ind
in
xrange
(
row_st
,
row_end
):
for
col_ind
in
xrange
(
col_st
,
col_end
):
if
(
maxout
[
n
,
k
,
r
,
c
]
==
y
[
n
,
k
,
row_ind
,
col_ind
]):
...
...
@@ -576,15 +576,15 @@ class DownsampleFactorMaxGrad(Op):
if
sum_mode
or
inc_pad
:
row_st
=
r
*
st0
else
:
row_st
=
__builtin__
.
max
(
r
*
st0
,
self
.
padding
[
0
])
row_end
=
__builtin__
.
min
(
row_st
+
ds0
,
img_rows
)
row_st
=
builtins
.
max
(
r
*
st0
,
self
.
padding
[
0
])
row_end
=
builtins
.
min
(
row_st
+
ds0
,
img_rows
)
for
c
in
xrange
(
pc
):
if
sum_mode
or
inc_pad
:
col_st
=
c
*
st1
else
:
col_st
=
__builtin__
.
max
(
c
*
st1
,
col_st
=
builtins
.
max
(
c
*
st1
,
self
.
padding
[
1
])
col_end
=
__builtin__
.
min
(
col_st
+
ds1
,
img_cols
)
col_end
=
builtins
.
min
(
col_st
+
ds1
,
img_cols
)
if
sum_mode
:
val
=
gz
[
n
,
k
,
r
,
c
]
else
:
...
...
@@ -628,7 +628,7 @@ class DownsampleFactorMaxGrad(Op):
int x_typenum = PyArray_ObjectType((PyObject*)
%(x)
s, 0);
int z_typenum = PyArray_ObjectType((PyObject*)
%(z)
s, 0);
int gz_typenum = PyArray_ObjectType((PyObject*)
%(gz)
s, 0);
if ((x_typenum != z_typenum) || (x_typenum != gz_typenum))
{
PyErr_SetString(PyExc_ValueError, "input types must all match");
...
...
@@ -649,11 +649,11 @@ class DownsampleFactorMaxGrad(Op):
PyErr_SetString(PyExc_ValueError, "gz must be a 4d ndarray");
%(fail)
s;
}
int z_r, z_c;
z_r = PyArray_DIMS(
%(z)
s)[2];
z_c = PyArray_DIMS(
%(z)
s)[3];
int r, c; // shape of the padded_input
r = PyArray_DIMS(
%(x)
s)[2];
c = PyArray_DIMS(
%(x)
s)[3];
...
...
@@ -698,7 +698,7 @@ class DownsampleFactorMaxGrad(Op):
// skip the padding
c_st = c_st <
%(pd1)
s ?
%(pd1)
s : c_st;
c_end = c_end > (c -
%(pd1)
s) ? c -
%(pd1)
s : c_end;
// change coordinates from padding_img space into img space
c_st -=
%(pd1)
s;
c_end -=
%(pd1)
s;
...
...
@@ -716,7 +716,7 @@ class DownsampleFactorMaxGrad(Op):
dtype_
%(gx)
s * gx = (
(dtype_
%(gx)
s*)(PyArray_GETPTR4(
%(gx)
s, b, k, m, n)));
if (a == maximum){
gx[0] = gx[0] + gz[0];
gx[0] = gx[0] + gz[0];
}
}
}
...
...
@@ -724,7 +724,7 @@ class DownsampleFactorMaxGrad(Op):
}
}
}
}
"""
%
locals
()
...
...
@@ -850,10 +850,10 @@ class DownsampleFactorMaxGradGrad(Op):
for
k
in
xrange
(
x
.
shape
[
1
]):
for
r
in
xrange
(
pr
):
row_st
=
r
*
st0
row_end
=
__builtin__
.
min
(
row_st
+
ds0
,
img_rows
)
row_end
=
builtins
.
min
(
row_st
+
ds0
,
img_rows
)
for
c
in
xrange
(
pc
):
col_st
=
c
*
st1
col_end
=
__builtin__
.
min
(
col_st
+
ds1
,
img_cols
)
col_end
=
builtins
.
min
(
col_st
+
ds1
,
img_cols
)
for
row_ind
in
xrange
(
row_st
,
row_end
):
for
col_ind
in
xrange
(
col_st
,
col_end
):
if
(
maxout
[
n
,
k
,
r
,
c
]
==
x
[
n
,
k
,
row_ind
,
col_ind
]):
...
...
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
030c7b96
from
itertools
import
product
import
unittest
import
__builtin__
import
theano.compat.six.moves.builtins
as
builtins
import
numpy
...
...
@@ -87,16 +87,16 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
for
k
in
numpy
.
ndindex
(
*
x
.
shape
[:
-
2
]):
for
i
in
range
(
output_val
.
shape
[
-
2
]):
ii_st
=
i
*
st
[
0
]
ii_end
=
__builtin__
.
min
(
ii_st
+
ds
[
0
],
img_rows
)
ii_end
=
builtins
.
min
(
ii_st
+
ds
[
0
],
img_rows
)
if
not
inc_pad
:
ii_st
=
__builtin__
.
max
(
ii_st
,
pad_h
)
ii_end
=
__builtin__
.
min
(
ii_end
,
h
+
pad_h
)
ii_st
=
builtins
.
max
(
ii_st
,
pad_h
)
ii_end
=
builtins
.
min
(
ii_end
,
h
+
pad_h
)
for
j
in
range
(
output_val
.
shape
[
-
1
]):
jj_st
=
j
*
st
[
1
]
jj_end
=
__builtin__
.
min
(
jj_st
+
ds
[
1
],
img_cols
)
jj_end
=
builtins
.
min
(
jj_st
+
ds
[
1
],
img_cols
)
if
not
inc_pad
:
jj_st
=
__builtin__
.
max
(
jj_st
,
pad_w
)
jj_end
=
__builtin__
.
min
(
jj_end
,
w
+
pad_w
)
jj_st
=
builtins
.
max
(
jj_st
,
pad_w
)
jj_end
=
builtins
.
min
(
jj_end
,
w
+
pad_w
)
patch
=
y
[
k
][
ii_st
:
ii_end
,
jj_st
:
jj_end
]
output_val
[
k
][
i
,
j
]
=
func
(
patch
)
return
output_val
...
...
@@ -158,10 +158,10 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
for
k
in
numpy
.
ndindex
(
*
input
.
shape
[:
-
2
]):
for
i
in
range
(
output_val
.
shape
[
-
2
]):
ii_st
=
i
*
st
[
0
]
ii_end
=
__builtin__
.
min
(
ii_st
+
ds
[
0
],
img_rows
)
ii_end
=
builtins
.
min
(
ii_st
+
ds
[
0
],
img_rows
)
for
j
in
range
(
output_val
.
shape
[
-
1
]):
jj_st
=
j
*
st
[
1
]
jj_end
=
__builtin__
.
min
(
jj_st
+
ds
[
1
],
img_cols
)
jj_end
=
builtins
.
min
(
jj_st
+
ds
[
1
],
img_cols
)
patch
=
input
[
k
][
ii_st
:
ii_end
,
jj_st
:
jj_end
]
output_val
[
k
][
i
,
j
]
=
func
(
patch
)
return
output_val
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
030c7b96
...
...
@@ -10,7 +10,7 @@ import warnings
from
copy
import
copy
,
deepcopy
from
itertools
import
izip
# Import builtin min to be able to use it after importing the tensor version.
from
__builtin__
import
min
as
builtin_min
from
theano.compat.six.moves.builtins
import
min
as
builtin_min
from
nose.tools
import
assert_raises
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
...
...
@@ -20,8 +20,8 @@ from numpy.testing.noseclasses import KnownFailureTest
from
distutils.version
import
LooseVersion
import
theano
from
theano.compat
import
PY3
,
exc_message
,
operator_div
,
reduce
from
theano.compat.six
import
StringIO
from
theano.compat
import
PY3
,
exc_message
,
operator_div
from
theano.compat.six
.moves
import
StringIO
,
reduce
from
theano
import
compile
,
config
,
function
,
gof
,
tensor
,
shared
from
theano.compile
import
DeepCopyOp
from
theano.compile.mode
import
get_default_mode
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
030c7b96
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
from
copy
import
copy
from
itertools
import
imap
import
unittest
...
...
@@ -718,9 +718,9 @@ class test_Prod(unittest.TestCase):
def
test_pickle_bug
(
self
):
# Regression test for bug fixed in 24d4fd291054.
o
=
Prod
()
s
=
cP
ickle
.
dumps
(
o
,
protocol
=-
1
)
o
=
cP
ickle
.
loads
(
s
)
cP
ickle
.
dumps
(
o
)
s
=
p
ickle
.
dumps
(
o
,
protocol
=-
1
)
o
=
p
ickle
.
loads
(
s
)
p
ickle
.
dumps
(
o
)
class
test_IsInf_IsNan
(
unittest
.
TestCase
):
...
...
theano/tensor/tests/test_gc.py
浏览文件 @
030c7b96
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
sys
import
numpy
import
theano
...
...
@@ -50,8 +50,8 @@ def test_gc_never_pickles_temporaries():
g
=
theano
.
function
([
x
],
r
,
mode
=
theano
.
Mode
(
optimizer
=
optimizer
,
linker
=
g_linker
))
len_pre_f
=
len
(
cP
ickle
.
dumps
(
f
))
len_pre_g
=
len
(
cP
ickle
.
dumps
(
g
))
len_pre_f
=
len
(
p
ickle
.
dumps
(
f
))
len_pre_g
=
len
(
p
ickle
.
dumps
(
g
))
# We can't compare the content or the length of the string
# between f and g. 2 reason, we store some timming information
...
...
@@ -59,19 +59,19 @@ def test_gc_never_pickles_temporaries():
# can have different lenght when printed.
def
a
(
fn
):
return
len
(
cP
ickle
.
dumps
(
fn
.
maker
))
return
len
(
p
ickle
.
dumps
(
fn
.
maker
))
assert
a
(
f
)
==
a
(
f
)
# some sanity checks on the pickling mechanism
assert
a
(
g
)
==
a
(
g
)
# some sanity checks on the pickling mechanism
def
b
(
fn
):
return
len
(
cP
ickle
.
dumps
(
p
ickle
.
dumps
(
theano
.
compile
.
function_module
.
_pickle_Function
(
fn
)))
assert
b
(
f
)
==
b
(
f
)
# some sanity checks on the pickling mechanism
def
c
(
fn
):
return
len
(
cP
ickle
.
dumps
(
fn
))
return
len
(
p
ickle
.
dumps
(
fn
))
assert
c
(
f
)
==
c
(
f
)
# some sanity checks on the pickling mechanism
assert
c
(
g
)
==
c
(
g
)
# some sanity checks on the pickling mechanism
...
...
@@ -81,8 +81,8 @@ def test_gc_never_pickles_temporaries():
g
(
numpy
.
ones
(
100
,
dtype
=
'float64'
))
# serialize the functions again
post_f
=
cP
ickle
.
dumps
(
f
)
post_g
=
cP
ickle
.
dumps
(
g
)
post_f
=
p
ickle
.
dumps
(
f
)
post_g
=
p
ickle
.
dumps
(
g
)
len_post_f
=
len
(
post_f
)
len_post_g
=
len
(
post_g
)
...
...
theano/tensor/tests/test_type_other.py
浏览文件 @
030c7b96
...
...
@@ -29,7 +29,7 @@ def test_none_Constant():
assert
o2
.
equals
(
NoneConst
)
# This trigger equals that returned the wrong answer in the past.
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
theano
from
theano
import
tensor
...
...
@@ -40,4 +40,4 @@ def test_none_Constant():
if
theano
.
config
.
mode
in
[
"DebugMode"
,
"DEBUG_MODE"
]:
kwargs
=
{
'mode'
:
'FAST_RUN'
}
f
=
theano
.
function
([
x
],
[
y
],
**
kwargs
)
cPickle
.
loads
(
cP
ickle
.
dumps
(
f
))
pickle
.
loads
(
p
ickle
.
dumps
(
f
))
theano/tests/run_tests_in_batch.py
浏览文件 @
030c7b96
...
...
@@ -55,7 +55,7 @@ nosetests.
"""
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
datetime
import
os
import
subprocess
...
...
@@ -155,7 +155,7 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
noseids_file
=
'.noseids'
with
open
(
noseids_file
,
'rb'
)
as
f
:
data
=
cP
ickle
.
load
(
f
)
data
=
p
ickle
.
load
(
f
)
ids
=
data
[
'ids'
]
n_tests
=
len
(
ids
)
...
...
@@ -198,7 +198,7 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
# seems like it is not systematically erased though, and we want
# to avoid duplicates.
with
open
(
noseids_file
,
'rb'
)
as
f
:
failed
=
failed
.
union
(
cP
ickle
.
load
(
f
)[
'failed'
])
failed
=
failed
.
union
(
p
ickle
.
load
(
f
)[
'failed'
])
print
(
'
%
s
%%
done in
%.3
fs (failed:
%
s)'
%
(
(
test_range
[
-
1
]
*
100
)
//
n_tests
,
t1
-
t0
,
len
(
failed
)))
...
...
theano/tests/test_pickle_unpickle_theano_fn.py
浏览文件 @
030c7b96
...
...
@@ -14,7 +14,7 @@ This note is written by Li Yao.
"""
import
unittest
import
numpy
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
from
theano.compat
import
DictMixin
,
OrderedDict
import
theano
import
theano.tensor
as
T
...
...
@@ -37,7 +37,7 @@ def test_pickle_unpickle_with_reoptimization():
f
=
theano
.
function
([
x1
,
x2
],
y
,
updates
=
updates
,
mode
=
mode
)
# now pickle the compiled theano fn
string_pkl
=
cP
ickle
.
dumps
(
f
,
-
1
)
string_pkl
=
p
ickle
.
dumps
(
f
,
-
1
)
in1
=
numpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
numpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
...
...
@@ -47,7 +47,7 @@ def test_pickle_unpickle_with_reoptimization():
try
:
# the default is True
theano
.
config
.
reoptimize_unpickled_function
=
True
f_
=
cP
ickle
.
loads
(
string_pkl
)
f_
=
p
ickle
.
loads
(
string_pkl
)
assert
f
(
in1
,
in2
)
==
f_
(
in1
,
in2
)
finally
:
theano
.
config
.
reoptimize_unpickled_function
=
default
...
...
@@ -69,7 +69,7 @@ def test_pickle_unpickle_without_reoptimization():
f
=
theano
.
function
([
x1
,
x2
],
y
,
updates
=
updates
,
mode
=
mode
)
# now pickle the compiled theano fn
string_pkl
=
cP
ickle
.
dumps
(
f
,
-
1
)
string_pkl
=
p
ickle
.
dumps
(
f
,
-
1
)
# compute f value
in1
=
numpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
...
...
@@ -80,7 +80,7 @@ def test_pickle_unpickle_without_reoptimization():
try
:
# the default is True
theano
.
config
.
reoptimize_unpickled_function
=
False
f_
=
cP
ickle
.
loads
(
string_pkl
)
f_
=
p
ickle
.
loads
(
string_pkl
)
assert
f
(
in1
,
in2
)
==
f_
(
in1
,
in2
)
finally
:
theano
.
config
.
reoptimize_unpickled_function
=
default
...
...
theano/tests/test_record.py
浏览文件 @
030c7b96
from
theano.tests.record
import
*
from
theano
import
function
from
theano.compat.six.moves
import
xrange
from
theano.compat.six.moves
import
xrange
,
StringIO
from
theano.tensor
import
iscalar
import
cStringIO
def
test_record_good
():
...
...
@@ -14,7 +13,7 @@ def test_record_good():
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
output
=
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
...
...
@@ -30,7 +29,7 @@ def test_record_good():
# Make sure that the playback functionality doesn't raise any errors
# when we repeat them
output
=
cStringIO
.
StringIO
(
output_value
)
output
=
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
...
...
@@ -45,7 +44,7 @@ def test_record_bad():
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
output
=
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
...
...
@@ -57,7 +56,7 @@ def test_record_bad():
# Make sure that the playback functionality doesn't raise any errors
# when we repeat some of them
output_value
=
output
.
getvalue
()
output
=
cStringIO
.
StringIO
(
output_value
)
output
=
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
...
...
@@ -81,7 +80,7 @@ def test_record_mode_good():
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
output
=
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
...
...
@@ -99,7 +98,7 @@ def test_record_mode_good():
# Make sure that the playback functionality doesn't raise any errors
# when we repeat them
output_value
=
output
.
getvalue
()
output
=
cStringIO
.
StringIO
(
output_value
)
output
=
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
...
...
@@ -121,7 +120,7 @@ def test_record_mode_bad():
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
output
=
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
...
...
@@ -139,7 +138,7 @@ def test_record_mode_bad():
# Make sure that the playback functionality doesn't raise any errors
# when we repeat them
output_value
=
output
.
getvalue
()
output
=
cStringIO
.
StringIO
(
output_value
)
output
=
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
...
...
theano/tests/test_tutorial.py
浏览文件 @
030c7b96
...
...
@@ -835,7 +835,7 @@ class T_loading_and_saving(unittest.TestCase):
def
test_loading_and_saving_1
(
self
):
import
cP
ickle
import
theano.compat.six.moves.cPickle
as
p
ickle
import
theano
,
theano
.
tensor
x
=
theano
.
tensor
.
matrix
()
...
...
@@ -856,11 +856,11 @@ class T_loading_and_saving(unittest.TestCase):
os
.
chdir
(
tmpdir
)
f
=
open
(
'obj.save'
,
'wb'
)
cPickle
.
dump
(
my_obj
,
f
,
protocol
=
cP
ickle
.
HIGHEST_PROTOCOL
)
pickle
.
dump
(
my_obj
,
f
,
protocol
=
p
ickle
.
HIGHEST_PROTOCOL
)
f
.
close
()
f
=
open
(
'obj.save'
,
'rb'
)
loaded_obj
=
cP
ickle
.
load
(
f
)
loaded_obj
=
p
ickle
.
load
(
f
)
f
.
close
()
obj1
=
my_obj
...
...
@@ -869,13 +869,13 @@ class T_loading_and_saving(unittest.TestCase):
f
=
open
(
'objects.save'
,
'wb'
)
for
obj
in
[
obj1
,
obj2
,
obj3
]:
cPickle
.
dump
(
obj
,
f
,
protocol
=
cP
ickle
.
HIGHEST_PROTOCOL
)
pickle
.
dump
(
obj
,
f
,
protocol
=
p
ickle
.
HIGHEST_PROTOCOL
)
f
.
close
()
f
=
open
(
'objects.save'
,
'rb'
)
loaded_objects
=
[]
for
i
in
range
(
3
):
loaded_objects
.
append
(
cP
ickle
.
load
(
f
))
loaded_objects
.
append
(
p
ickle
.
load
(
f
))
f
.
close
()
finally
:
# Get back to the orinal dir, and temporary one.
...
...
theano/tests/unittest_tools.py
浏览文件 @
030c7b96
...
...
@@ -2,7 +2,7 @@ from __future__ import print_function
from
copy
import
copy
,
deepcopy
from
functools
import
wraps
import
logging
from
StringIO
import
StringIO
from
io
import
StringIO
import
sys
import
unittest
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论