提交 a85ef2a0 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #4310 from nouiz/small

Small changes.
...@@ -965,8 +965,14 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -965,8 +965,14 @@ class Op(utils.object2, PureOp, CLinkerOp):
compute_map=compute_map) compute_map=compute_map)
if new_node is not None: if new_node is not None:
node = new_node node = new_node
if not hasattr(self, '_op_use_c_code'):
if self._op_use_c_code: warnings.warn(
"The __getstate__ method of '%s' is not implemented correctly."
" It should keep the attributes added by the base class."
" To implement it correctly, it should keep all attributes"
" and only remove those it does not want." % (self),
stacklevel=2)
if getattr(self, '_op_use_c_code', theano.config.cxx):
try: try:
return self.make_c_thunk(node, storage_map, compute_map, return self.make_c_thunk(node, storage_map, compute_map,
no_recycling) no_recycling)
......
...@@ -19,9 +19,9 @@ msgs=['Theano buildbot', ...@@ -19,9 +19,9 @@ msgs=['Theano buildbot',
'Deep Learning Tutorial buildbot', 'Deep Learning Tutorial buildbot',
'Theano Python3.3.0 buildbot'] 'Theano Python3.3.0 buildbot']
print 'files', files print('files', files)
print "msgs", msgs print("msgs", msgs)
print "args", sys.argv print("args", sys.argv)
if len(sys.argv) == 3: if len(sys.argv) == 3:
#We send just a file with a message #We send just a file with a message
files = [sys.argv[1]] files = [sys.argv[1]]
...@@ -31,7 +31,7 @@ elif len(sys.argv) == 2: ...@@ -31,7 +31,7 @@ elif len(sys.argv) == 2:
files=[os.path.join(sys.argv[1], x) for x in files] files=[os.path.join(sys.argv[1], x) for x in files]
else: else:
files=[os.path.join('/tmp', x) for x in files] files=[os.path.join('/tmp', x) for x in files]
print 'path', files print('path', files)
# Here are the email package modules we'll need # Here are the email package modules we'll need
from email.mime.text import MIMEText from email.mime.text import MIMEText
...@@ -42,7 +42,7 @@ COMMASPACE = ', ' ...@@ -42,7 +42,7 @@ COMMASPACE = ', '
def mysend(subject, file): def mysend(subject, file):
# Create the container (outer) email message. # Create the container (outer) email message.
if not os.path.isfile(file): if not os.path.isfile(file):
print "Error: no file",file print("Error: no file", file)
return return
msg = MIMEMultipart() msg = MIMEMultipart()
...@@ -89,8 +89,8 @@ def mysend(subject, file): ...@@ -89,8 +89,8 @@ def mysend(subject, file):
ran=False ran=False
try: try:
nb_ran+=int(token) nb_ran+=int(token)
except Exception, e: except Exception as e:
print e print(e)
start = "" start = ""
for line in s.splitlines(): for line in s.splitlines():
...@@ -124,12 +124,12 @@ def mysend(subject, file): ...@@ -124,12 +124,12 @@ def mysend(subject, file):
else: else:
msg['Subject'] = subject+" Fail="+str(failures)+" Err="+str(errors)+" Ran="+str(nb_ran)+" Skip="+str(skip)+" KnownFail="+str(knownfail) msg['Subject'] = subject+" Fail="+str(failures)+" Err="+str(errors)+" Ran="+str(nb_ran)+" Skip="+str(skip)+" KnownFail="+str(knownfail)
print msg['Subject'] print(msg['Subject'])
s = smtplib.SMTP() s = smtplib.SMTP()
s.connect() s.connect()
s.sendmail(me, family, msg.as_string()) s.sendmail(me, family, msg.as_string())
s.close() s.close()
print "Finished sending email for",subject print("Finished sending email for", subject)
for msg, file in zip(msgs, files): for msg, file in zip(msgs, files):
mysend(msg, file) mysend(msg, file)
...@@ -568,11 +568,11 @@ class test_DnnSoftMax(test_nnet.test_SoftMax): ...@@ -568,11 +568,11 @@ class test_DnnSoftMax(test_nnet.test_SoftMax):
x_val = numpy.random.normal(0, 1, (3, 4, 2, 5)).astype('float32') x_val = numpy.random.normal(0, 1, (3, 4, 2, 5)).astype('float32')
x_val2 = numpy.random.normal(0, 1, (3, 4, 1, 1)).astype('float32') x_val2 = numpy.random.normal(0, 1, (3, 4, 1, 1)).astype('float32')
utt.verify_grad(softmax_op, [x_val]) utt.verify_grad(softmax_op, [x_val], mode=mode_with_gpu)
# Gradient is broken for (n, c, 1, 1) in v3 rc1 # Gradient is broken for (n, c, 1, 1) in v3 rc1
if cuda.dnn.version() != (3000, 3000): if cuda.dnn.version() != (3000, 3000):
utt.verify_grad(softmax_op, [x_val2]) utt.verify_grad(softmax_op, [x_val2], mode=mode_with_gpu)
def test_cudnn_softmax_grad_opt(self): def test_cudnn_softmax_grad_opt(self):
# Verify that the SoftmaxGrad -> GpuDnnSoftmaxGrad optimization is # Verify that the SoftmaxGrad -> GpuDnnSoftmaxGrad optimization is
...@@ -1353,9 +1353,9 @@ def test_dnn_conv_grad(): ...@@ -1353,9 +1353,9 @@ def test_dnn_conv_grad():
return dnn.GpuDnnConvGradW()(img, out, kern, desc, alpha=0.75, return dnn.GpuDnnConvGradW()(img, out, kern, desc, alpha=0.75,
beta=-1.0) beta=-1.0)
utt.verify_grad(dconv, [img_val, kern_val, out_val]) utt.verify_grad(dconv, [img_val, kern_val, out_val], mode=mode_with_gpu)
utt.verify_grad(dconvi, [img_val, kern_val, out_val]) utt.verify_grad(dconvi, [img_val, kern_val, out_val], mode=mode_with_gpu)
utt.verify_grad(dconvw, [img_val, kern_val, out_val]) utt.verify_grad(dconvw, [img_val, kern_val, out_val], mode=mode_with_gpu)
def get_conv3d_test_cases(): def get_conv3d_test_cases():
......
...@@ -140,7 +140,10 @@ class DimShuffle(Op): ...@@ -140,7 +140,10 @@ class DimShuffle(Op):
# numpy integers. See # numpy integers. See
# <http://projects.scipy.org/numpy/ticket/2235>. # <http://projects.scipy.org/numpy/ticket/2235>.
if not isinstance(j, (integer_types, numpy.integer)): if not isinstance(j, (integer_types, numpy.integer)):
raise TypeError("DimShuffle indices must be python ints.") raise TypeError(
"DimShuffle indices must be python ints. "
"Got: '%s' of type '%s'.",
str(j), str(type(j)))
if j >= len(input_broadcastable): if j >= len(input_broadcastable):
raise ValueError(("new_order[%d] is %d, but the input " raise ValueError(("new_order[%d] is %d, but the input "
"only has %d axes.") % "only has %d axes.") %
......
...@@ -133,15 +133,27 @@ class RandomFunction(gof.Op): ...@@ -133,15 +133,27 @@ class RandomFunction(gof.Op):
self.__setstate__([fn, outtype, inplace, ndim_added]) self.__setstate__([fn, outtype, inplace, ndim_added])
def __getstate__(self): def __getstate__(self):
return self.state d = dict(self.__dict__)
del d['exec_fn']
def __setstate__(self, state): if 'destroy_map' in d:
self.state = state del d['destroy_map']
return d
def __setstate__(self, dct):
if isinstance(dct, dict):
state = [dct['fn'],
dct['outtype'],
dct['inplace'],
dct['ndim_added']]
self.__dict__.update(dct)
else:
state = dct
fn, outtype, inplace, ndim_added = state fn, outtype, inplace, ndim_added = state
self.fn = fn
if isinstance(fn, string_types): if isinstance(fn, string_types):
self.fn = getattr(numpy.random.RandomState, fn) self.exec_fn = getattr(numpy.random.RandomState, fn)
else: else:
self.fn = fn self.exec_fn = fn
self.outtype = outtype self.outtype = outtype
self.inplace = inplace self.inplace = inplace
if self.inplace: if self.inplace:
...@@ -149,7 +161,7 @@ class RandomFunction(gof.Op): ...@@ -149,7 +161,7 @@ class RandomFunction(gof.Op):
self.ndim_added = ndim_added self.ndim_added = ndim_added
def __str__(self): def __str__(self):
return 'RandomFunction{%s}' % self.fn.__name__ return 'RandomFunction{%s}' % self.exec_fn.__name__
def make_node(self, r, shape, *args): def make_node(self, r, shape, *args):
""" """
...@@ -247,7 +259,7 @@ class RandomFunction(gof.Op): ...@@ -247,7 +259,7 @@ class RandomFunction(gof.Op):
if not self.inplace: if not self.inplace:
r = copy(r) r = copy(r)
rout[0] = r rout[0] = r
rval = self.fn(r, *(args + [shape])) rval = self.exec_fn(r, *(args + [shape]))
if (not isinstance(rval, numpy.ndarray) or if (not isinstance(rval, numpy.ndarray) or
str(rval.dtype) != node.outputs[1].type.dtype): str(rval.dtype) != node.outputs[1].type.dtype):
rval = theano._asarray(rval, dtype=node.outputs[1].type.dtype) rval = theano._asarray(rval, dtype=node.outputs[1].type.dtype)
...@@ -904,7 +916,7 @@ def random_make_inplace(node): ...@@ -904,7 +916,7 @@ def random_make_inplace(node):
if isinstance(op, RandomFunction) and not op.inplace: if isinstance(op, RandomFunction) and not op.inplace:
# Read op_fn from op.state, not from op.fn, since op.fn # Read op_fn from op.state, not from op.fn, since op.fn
# may not be picklable. # may not be picklable.
op_fn, op_outtype, op_inplace, op_ndim_added = op.__getstate__() op_fn, op_outtype, op_inplace, op_ndim_added = op._props()
new_op = RandomFunction(op_fn, op_outtype, inplace=True, new_op = RandomFunction(op_fn, op_outtype, inplace=True,
ndim_added=op_ndim_added) ndim_added=op_ndim_added)
return new_op.make_node(*node.inputs).outputs return new_op.make_node(*node.inputs).outputs
......
...@@ -310,8 +310,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -310,8 +310,6 @@ class T_random_function(utt.InferShapeTester):
self.assertRaises(ValueError, fm11) self.assertRaises(ValueError, fm11)
self.assertRaises(ValueError, fm12) self.assertRaises(ValueError, fm12)
u01, u02 = f0() u01, u02 = f0()
print(u01)
print(u02)
self.assertTrue(numpy.allclose(u01, u02[0])) self.assertTrue(numpy.allclose(u01, u02[0]))
def test_uniform(self): def test_uniform(self):
...@@ -332,10 +330,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -332,10 +330,6 @@ class T_random_function(utt.InferShapeTester):
val1 = f() val1 = f()
numpy_val0 = numpy_rng.uniform(-2.0, 2.0, size=(4,)) numpy_val0 = numpy_rng.uniform(-2.0, 2.0, size=(4,))
numpy_val1 = numpy_rng.uniform(-2.0, 2.0, size=(4,)) numpy_val1 = numpy_rng.uniform(-2.0, 2.0, size=(4,))
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.allclose(val0, numpy_val0)) self.assertTrue(numpy.allclose(val0, numpy_val0))
self.assertTrue(numpy.allclose(val1, numpy_val1)) self.assertTrue(numpy.allclose(val1, numpy_val1))
...@@ -359,10 +353,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -359,10 +353,6 @@ class T_random_function(utt.InferShapeTester):
val1 = f() val1 = f()
numpy_val0 = numpy_rng.binomial(5, 0.8, size=(7, 12)) numpy_val0 = numpy_rng.binomial(5, 0.8, size=(7, 12))
numpy_val1 = numpy_rng.binomial(5, 0.8, size=(7, 12)) numpy_val1 = numpy_rng.binomial(5, 0.8, size=(7, 12))
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.all(val0 == numpy_val0)) self.assertTrue(numpy.all(val0 == numpy_val0))
self.assertTrue(numpy.all(val1 == numpy_val1)) self.assertTrue(numpy.all(val1 == numpy_val1))
...@@ -384,10 +374,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -384,10 +374,6 @@ class T_random_function(utt.InferShapeTester):
val1 = f() val1 = f()
numpy_val0 = numpy_rng.normal(4.0, 2.0, size=(2, 3)) numpy_val0 = numpy_rng.normal(4.0, 2.0, size=(2, 3))
numpy_val1 = numpy_rng.normal(4.0, 2.0, size=(2, 3)) numpy_val1 = numpy_rng.normal(4.0, 2.0, size=(2, 3))
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.allclose(val0, numpy_val0)) self.assertTrue(numpy.allclose(val0, numpy_val0))
self.assertTrue(numpy.allclose(val1, numpy_val1)) self.assertTrue(numpy.allclose(val1, numpy_val1))
...@@ -411,10 +397,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -411,10 +397,6 @@ class T_random_function(utt.InferShapeTester):
val1 = f() val1 = f()
numpy_val0 = numpy_rng.random_integers(-3, 16, size=(11, 8)) numpy_val0 = numpy_rng.random_integers(-3, 16, size=(11, 8))
numpy_val1 = numpy_rng.random_integers(-3, 16, size=(11, 8)) numpy_val1 = numpy_rng.random_integers(-3, 16, size=(11, 8))
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.allclose(val0, numpy_val0)) self.assertTrue(numpy.allclose(val0, numpy_val0))
self.assertTrue(numpy.allclose(val1, numpy_val1)) self.assertTrue(numpy.allclose(val1, numpy_val1))
...@@ -447,10 +429,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -447,10 +429,6 @@ class T_random_function(utt.InferShapeTester):
for i in range(7)]) for i in range(7)])
numpy_val1 = numpy.asarray([numpy_rng.permutation(8) numpy_val1 = numpy.asarray([numpy_rng.permutation(8)
for i in range(7)]) for i in range(7)])
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.all(val0 == numpy_val0)) self.assertTrue(numpy.all(val0 == numpy_val0))
self.assertTrue(numpy.all(val1 == numpy_val1)) self.assertTrue(numpy.all(val1 == numpy_val1))
...@@ -502,10 +480,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -502,10 +480,6 @@ class T_random_function(utt.InferShapeTester):
val1 = f() val1 = f()
numpy_val0 = numpy_rng.choice(10, (11, 8), True, None) numpy_val0 = numpy_rng.choice(10, (11, 8), True, None)
numpy_val1 = numpy_rng.choice(10, (11, 8), True, None) numpy_val1 = numpy_rng.choice(10, (11, 8), True, None)
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.allclose(val0, numpy_val0)) self.assertTrue(numpy.allclose(val0, numpy_val0))
self.assertTrue(numpy.allclose(val1, numpy_val1)) self.assertTrue(numpy.allclose(val1, numpy_val1))
...@@ -529,10 +503,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -529,10 +503,6 @@ class T_random_function(utt.InferShapeTester):
val1 = f() val1 = f()
numpy_val0 = numpy_rng.poisson(5, size=(11, 8)) numpy_val0 = numpy_rng.poisson(5, size=(11, 8))
numpy_val1 = numpy_rng.poisson(5, size=(11, 8)) numpy_val1 = numpy_rng.poisson(5, size=(11, 8))
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.allclose(val0, numpy_val0)) self.assertTrue(numpy.allclose(val0, numpy_val0))
self.assertTrue(numpy.allclose(val1, numpy_val1)) self.assertTrue(numpy.allclose(val1, numpy_val1))
...@@ -541,7 +511,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -541,7 +511,6 @@ class T_random_function(utt.InferShapeTester):
results as numpy.""" results as numpy."""
rng_R = random_state_type() rng_R = random_state_type()
post_r, out = permutation(rng_R, size=(9,), n=6) post_r, out = permutation(rng_R, size=(9,), n=6)
print('OUT NDIM', out.ndim)
f = compile.function( f = compile.function(
[compile.In(rng_R, [compile.In(rng_R,
value=numpy.random.RandomState(utt.fetch_seed()), value=numpy.random.RandomState(utt.fetch_seed()),
...@@ -558,10 +527,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -558,10 +527,6 @@ class T_random_function(utt.InferShapeTester):
for i in range(9)]) for i in range(9)])
numpy_val1 = numpy.asarray([numpy_rng.permutation(6) numpy_val1 = numpy.asarray([numpy_rng.permutation(6)
for i in range(9)]) for i in range(9)])
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.all(val0 == numpy_val0)) self.assertTrue(numpy.all(val0 == numpy_val0))
self.assertTrue(numpy.all(val1 == numpy_val1)) self.assertTrue(numpy.all(val1 == numpy_val1))
...@@ -596,10 +561,6 @@ class T_random_function(utt.InferShapeTester): ...@@ -596,10 +561,6 @@ class T_random_function(utt.InferShapeTester):
val1, = f() val1, = f()
numpy_val0 = numpy_rng.multinomial(6, [0.2] * 5, (7, 3)) numpy_val0 = numpy_rng.multinomial(6, [0.2] * 5, (7, 3))
numpy_val1 = numpy_rng.multinomial(6, [0.2] * 5, (7, 3)) numpy_val1 = numpy_rng.multinomial(6, [0.2] * 5, (7, 3))
print(val0)
print(numpy_val0)
print(val1)
print(numpy_val1)
self.assertTrue(numpy.all(val0 == numpy_val0)) self.assertTrue(numpy.all(val0 == numpy_val0))
self.assertTrue(numpy.all(val1 == numpy_val1)) self.assertTrue(numpy.all(val1 == numpy_val1))
...@@ -1199,6 +1160,7 @@ class T_random_function(utt.InferShapeTester): ...@@ -1199,6 +1160,7 @@ class T_random_function(utt.InferShapeTester):
post_int_r, int_sample = random_integers(rng_r, (3, 5), -1, 8) post_int_r, int_sample = random_integers(rng_r, (3, 5), -1, 8)
g = theano.function([rng_r], [post_int_r, int_sample], mode=mode) g = theano.function([rng_r], [post_int_r, int_sample], mode=mode)
pkl_g = pickle.dumps(g) pkl_g = pickle.dumps(g)
pickle.loads(pkl_g)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论