提交 030c7b96 authored 作者: David Warde-Farley's avatar David Warde-Farley 提交者: Arnaud Bergeron

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