提交 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
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)
########################
#
......
"""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:
cPickle.dump(d, f, -1)
pickle.dump(d, f, -1)
def function(inputs, outputs=None, mode=None, updates=None, givens=None,
......
......@@ -3,8 +3,8 @@
from __future__ import print_function
import copy
import copy_reg
import cPickle
import theano.compat.six.moves.copyreg as copyreg
import theano.compat.six.moves.cPickle as pickle
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 = cPickle.load(f)
graph_db = pickle.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')
cPickle.dump(graph_db, f, -1)
pickle.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 = []
......
......@@ -4,7 +4,7 @@ and Ops building class (:class:`FromFunctionOp`) and decorator
"""
import copy
import cPickle
import theano.compat.six.moves.cPickle as pickle
import warnings
import theano
......@@ -517,12 +517,12 @@ class FromFunctionOp(gof.Op):
try:
obj = load_back(mod, name)
except (ImportError, KeyError, AttributeError):
raise cPickle.PicklingError(
raise pickle.PicklingError(
"Can't pickle as_op(), not found as %s.%s" %
(mod, name))
else:
if obj is not self:
raise cPickle.PicklingError(
raise pickle.PicklingError(
"Can't pickle as_op(), not the object "
"at %s.%s" % (mod, name))
return load_back, (mod, name)
......
import cPickle
import theano.compat.six.moves.cPickle as pickle
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 = cPickle.load(f)
l = pickle.load(f)
f.close()
finally:
if tmpdir is not None:
......
import copy
import cPickle
import theano.compat.six.moves.cPickle as pickle
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(cPickle.dumps(f, protocol=0))
g = cPickle.loads(cPickle.dumps(f, protocol=-1))
g = pickle.loads(pickle.dumps(f, protocol=0))
g = pickle.loads(pickle.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 = cPickle.dumps(f, protocol=-1)
str_f = pickle.dumps(f, protocol=-1)
config.mode = 'Mode'
config.linker = 'py'
config.optimizer = 'None'
g = cPickle.loads(str_f)
g = pickle.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 = cPickle.dumps(list_of_things, protocol=-1)
new_list_of_things = cPickle.loads(saved_format)
saved_format = pickle.dumps(list_of_things, protocol=-1)
new_list_of_things = pickle.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 = cPickle.Pickler(fp, 2)
p = pickle.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 = cPickle.Unpickler(fp2)
p = pickle.Unpickler(fp2)
p.persistent_load = pers_load
f2 = p.load()
fp2.close()
......
......@@ -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
......
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 = cPickle.load(f)
self.cache = pickle.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')
cPickle.dump(self.cache, f)
pickle.dump(self.cache, f)
f.close()
def call(self, fn, args=(), key=None):
......
......@@ -2,7 +2,7 @@
"""
from __future__ import print_function
import atexit
import cPickle
import theano.compat.six.moves.cPickle as pickle
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=cPickle.HIGHEST_PROTOCOL)
except cPickle.PicklingError:
pickle.dump(self, f, protocol=pickle.HIGHEST_PROTOCOL)
except pickle.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 = cPickle.load(f)
key_data = pickle.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 cPickle.PicklingError:
except pickle.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 cPickle.PicklingError:
except pickle.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 = cPickle.load(f)
key_data = pickle.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 = cPickle.load(f)
key_data = pickle.load(f)
time.sleep(2)
found = sum(key == other_key for other_key in key_data.keys)
......
from __future__ import print_function
import cPickle
import theano.compat.six.moves.cPickle as pickle
import errno
import logging
import os
......@@ -280,7 +280,7 @@ def cleanup():
file = open(filename, 'rb')
# print file
try:
keydata = cPickle.load(file)
keydata = pickle.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 = cPickle.load(file)
keydata = pickle.load(file)
ops = list(set([x for x in flatten(keydata.keys)
if isinstance(x, theano.gof.Op)]))
if len(ops) == 0:
......
......@@ -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 += "\nBacktrace when the variable is created:\n"
......
......@@ -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 += "\nBacktrace 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 += "\nDebugprint of the apply node: \n"
......
......@@ -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 += (
......
import unittest, os
import numpy
import cPickle
import theano.compat.six.moves.cPickle as pickle
from theano.compat import DictMixin, OrderedDict
import theano
import theano.tensor as T
......
"""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 '
......
from __future__ import print_function
import cPickle
import theano.compat.six.moves.cPickle as pickle
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, cPickle.loads(k)))
print("Duplicate key (%i copies): %s" % (v, pickle.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 = cPickle.loads(kk)
kk = pickle.loads(kk)
print(kk)
print("key.pkl histograph")
......
......@@ -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
......
import cPickle
import theano.compat.six.moves.cPickle as pickle
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
......
......@@ -2,7 +2,7 @@
"""
from __future__ import print_function
import os
import copy_reg
import theano.compat.six.moves.copyreg as copyreg
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)
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)
......
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];
......
......@@ -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 = ""
......
......@@ -6,7 +6,7 @@ import time
import sys
import unittest
import cPickle
import theano.compat.six.moves.cPickle as pickle
import numpy
from numpy.testing import dec
......
import cPickle
import theano.compat.six.moves.cPickle as pickle
import numpy
import unittest
......
......@@ -7,7 +7,7 @@ import time
import unittest
import copy
import cPickle
import theano.compat.six.moves.cPickle as pickle
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:
cPickle.dump(_my_f, f_out, protocol=-1)
pickle.dump(_my_f, f_out, protocol=-1)
finally:
f_out.close()
f_in = open('tmp_scan_test_pickle.pkl', 'rb')
try:
my_f = cPickle.load(f_in)
my_f = pickle.load(f_in)
finally:
f_in.close()
finally:
......
......@@ -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]):
......
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
......
......@@ -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
......
import cPickle
import theano.compat.six.moves.cPickle as pickle
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 = cPickle.dumps(o, protocol=-1)
o = cPickle.loads(s)
cPickle.dumps(o)
s = pickle.dumps(o, protocol=-1)
o = pickle.loads(s)
pickle.dumps(o)
class test_IsInf_IsNan(unittest.TestCase):
......
import cPickle
import theano.compat.six.moves.cPickle as pickle
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(cPickle.dumps(f))
len_pre_g = len(cPickle.dumps(g))
len_pre_f = len(pickle.dumps(f))
len_pre_g = len(pickle.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(cPickle.dumps(fn.maker))
return len(pickle.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(
cPickle.dumps(
pickle.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(cPickle.dumps(fn))
return len(pickle.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 = cPickle.dumps(f)
post_g = cPickle.dumps(g)
post_f = pickle.dumps(f)
post_g = pickle.dumps(g)
len_post_f = len(post_f)
len_post_g = len(post_g)
......
......@@ -29,7 +29,7 @@ def test_none_Constant():
assert o2.equals(NoneConst)
# This trigger equals that returned the wrong answer in the past.
import cPickle
import theano.compat.six.moves.cPickle as pickle
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(cPickle.dumps(f))
pickle.loads(pickle.dumps(f))
......@@ -55,7 +55,7 @@ nosetests.
"""
import cPickle
import theano.compat.six.moves.cPickle as pickle
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 = cPickle.load(f)
data = pickle.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(cPickle.load(f)['failed'])
failed = failed.union(pickle.load(f)['failed'])
print('%s%% done in %.3fs (failed: %s)' % (
(test_range[-1] * 100) // n_tests, t1 - t0, len(failed)))
......
......@@ -14,7 +14,7 @@ This note is written by Li Yao.
"""
import unittest
import numpy
import cPickle
import theano.compat.six.moves.cPickle as pickle
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 = cPickle.dumps(f, -1)
string_pkl = pickle.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_ = cPickle.loads(string_pkl)
f_ = pickle.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 = cPickle.dumps(f, -1)
string_pkl = pickle.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_ = cPickle.loads(string_pkl)
f_ = pickle.loads(string_pkl)
assert f(in1, in2) == f_(in1, in2)
finally:
theano.config.reoptimize_unpickled_function = default
......
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)
......
......@@ -835,7 +835,7 @@ class T_loading_and_saving(unittest.TestCase):
def test_loading_and_saving_1(self):
import cPickle
import theano.compat.six.moves.cPickle as pickle
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=cPickle.HIGHEST_PROTOCOL)
pickle.dump(my_obj, f, protocol=pickle.HIGHEST_PROTOCOL)
f.close()
f = open('obj.save', 'rb')
loaded_obj = cPickle.load(f)
loaded_obj = pickle.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=cPickle.HIGHEST_PROTOCOL)
pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL)
f.close()
f = open('objects.save', 'rb')
loaded_objects = []
for i in range(3):
loaded_objects.append(cPickle.load(f))
loaded_objects.append(pickle.load(f))
f.close()
finally:
# Get back to the orinal dir, and temporary one.
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论