提交 76da3f78 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

PEP8

上级 94ee7a57
...@@ -3179,61 +3179,63 @@ class T_local_sum_dimshuffle(unittest.TestCase): ...@@ -3179,61 +3179,63 @@ class T_local_sum_dimshuffle(unittest.TestCase):
d = T.scalar('d') d = T.scalar('d')
sum = tensor.sum sum = tensor.sum
sums = [ sums = [
sum(a/d), sum(a / d),
sum(a/d.dimshuffle('x','x')), sum(a / d.dimshuffle('x', 'x')),
sum(a/d.dimshuffle('x','x'), axis=0), sum(a / d.dimshuffle('x', 'x'), axis=0),
sum(a/d.dimshuffle('x','x'), axis=1), sum(a / d.dimshuffle('x', 'x'), axis=1),
sum(b/d), sum(b / d),
sum(b/d.dimshuffle('x')), sum(b / d.dimshuffle('x')),
sum(c/d), sum(c / d),
sum(c/d.dimshuffle('x','x','x')), sum(c / d.dimshuffle('x', 'x', 'x')),
sum(c/d.dimshuffle('x','x','x'),axis=0), sum(c / d.dimshuffle('x', 'x', 'x'), axis=0),
sum(c/d.dimshuffle('x','x','x'),axis=1), sum(c / d.dimshuffle('x', 'x', 'x'), axis=1),
sum(c/d.dimshuffle('x','x','x'),axis=2), sum(c / d.dimshuffle('x', 'x', 'x'), axis=2),
sum(a / b, axis=0), sum(a / b, axis=0),
sum(a / b.dimshuffle(0,'x'), axis=1), sum(a / b.dimshuffle(0, 'x'), axis=1),
sum(a.dimshuffle(0,1)/ b.dimshuffle(0,'x'), axis=1), sum(a.dimshuffle(0, 1) / b.dimshuffle(0, 'x'), axis=1),
sum(a.dimshuffle(1,0)/ b.dimshuffle(0,'x'), axis=1), sum(a.dimshuffle(1, 0) / b.dimshuffle(0, 'x'), axis=1),
sum(c / a, axis=0), sum(c / a, axis=0),
sum(c / a.dimshuffle(1, 0), axis=0), sum(c / a.dimshuffle(1, 0), axis=0),
sum(c / a.dimshuffle(0,'x',1), axis=1), sum(c / a.dimshuffle(0, 'x', 1), axis=1),
sum(c / a.dimshuffle(1,'x',0), axis=1), sum(c / a.dimshuffle(1, 'x', 0), axis=1),
sum(c / a.dimshuffle(0, 1, 'x'), axis=2), sum(c / a.dimshuffle(0, 1, 'x'), axis=2),
sum(c / a.dimshuffle(1, 0, 'x'), axis=2), sum(c / a.dimshuffle(1, 0, 'x'), axis=2),
sum(c / b, axis=0), sum(c / b, axis=0),
sum(c / b, axis=1), sum(c / b, axis=1),
sum(c / b, axis=(0,1)), sum(c / b, axis=(0, 1)),
sum(c / b.dimshuffle(0,'x'), axis=0), sum(c / b.dimshuffle(0, 'x'), axis=0),
sum(c / b.dimshuffle(0,'x'), axis=2), sum(c / b.dimshuffle(0, 'x'), axis=2),
sum(c / b.dimshuffle(0,'x'), axis=(0,2)), sum(c / b.dimshuffle(0, 'x'), axis=(0, 2)),
sum(c / b.dimshuffle(0,'x','x'), axis=1), sum(c / b.dimshuffle(0, 'x', 'x'), axis=1),
sum(c / b.dimshuffle(0,'x','x'), axis=2), sum(c / b.dimshuffle(0, 'x', 'x'), axis=2),
sum(c / b.dimshuffle(0,'x','x'), axis=(1,2)), sum(c / b.dimshuffle(0, 'x', 'x'), axis=(1, 2)),
sum(sum(c, axis=0) / b, axis=0), sum(sum(c, axis=0) / b, axis=0),
sum(sum(c, axis=1) / b, axis=0), sum(sum(c, axis=1) / b, axis=0),
] ]
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
a_val = rng.randn(2,2).astype(config.floatX) a_val = rng.randn(2, 2).astype(config.floatX)
b_val = rng.randn(2).astype(config.floatX) b_val = rng.randn(2).astype(config.floatX)
c_val = rng.randn(2,2,2).astype(config.floatX) c_val = rng.randn(2, 2, 2).astype(config.floatX)
d_val = numpy.asarray(rng.randn(), config.floatX) d_val = numpy.asarray(rng.randn(), config.floatX)
backup = config.warn.sum_sum_bug, config.warn.sum_div_dimshuffle_bug backup = config.warn.sum_sum_bug, config.warn.sum_div_dimshuffle_bug
config.warn.sum_sum_bug = False config.warn.sum_sum_bug = False
config.warn.sum_div_dimshuffle_bug = False config.warn.sum_div_dimshuffle_bug = False
try: try:
for i,s in enumerate(sums): for i, s in enumerate(sums):
print i print i
f = theano.function([a,b,c,d], s, mode=self.mode) f = theano.function([a, b, c, d], s, mode=self.mode)
theano.printing.debugprint(f) theano.printing.debugprint(f)
g = f.maker.env.toposort() g = f.maker.env.toposort()
#print 'g =', g #print 'g =', g
assert isinstance(g[-1].op.scalar_op, theano.scalar.basic.TrueDiv) assert isinstance(g[-1].op.scalar_op,
theano.scalar.basic.TrueDiv)
f(a_val, b_val, c_val, d_val) f(a_val, b_val, c_val, d_val)
finally: finally:
config.warn.sum_sum_bug, config.warn.sum_div_dimshuffle_bug = backup config.warn.sum_sum_bug, config.warn.sum_div_dimshuffle_bug =\
backup
# TODO: # TODO:
# test_local_sum_prod_dimshuffle (a * b * c) # test_local_sum_prod_dimshuffle (a * b * c)
...@@ -3251,22 +3253,21 @@ def test_make_vector(): ...@@ -3251,22 +3253,21 @@ def test_make_vector():
d: 0.7} d: 0.7}
# Should work # Should work
for (dtype, inputs) in [("int8", (b,b)), for (dtype, inputs) in [("int8", (b, b)),
("int32", (i,b)), ("int32", (i, b)),
("int32", (b,i)), ("int32", (b, i)),
("float64", (b,i)), ("float64", (b, i)),
("float64", (b,d)), ("float64", (b, d)),
("float64", (d,i)), ("float64", (d, i)),
("float64", ()), ("float64", ()),
("int64", ()), ("int64", ()),
]: ]:
mv = opt.MakeVector(dtype=dtype)(*inputs) mv = opt.MakeVector(dtype=dtype)(*inputs)
assert mv.dtype == dtype assert mv.dtype == dtype
f = theano.function([b,i,d], mv) f = theano.function([b, i, d], mv)
f_val = f(val[b], val[i], val[d]) f_val = f(val[b], val[i], val[d])
#print 'f_val =', f_val #print 'f_val =', f_val
s = mv.sum() s = mv.sum()
gb = T.grad(s, b, disconnected_inputs='ignore') gb = T.grad(s, b, disconnected_inputs='ignore')
gi = T.grad(s, i, disconnected_inputs='ignore') gi = T.grad(s, i, disconnected_inputs='ignore')
...@@ -3275,7 +3276,7 @@ def test_make_vector(): ...@@ -3275,7 +3276,7 @@ def test_make_vector():
#print 'gi =', gi #print 'gi =', gi
#print 'gd =', gd #print 'gd =', gd
g = theano.function([b,i,d], [gb, gi, gd]) g = theano.function([b, i, d], [gb, gi, gd])
g_val = g(val[b], val[i], val[d]) g_val = g(val[b], val[i], val[d])
#print 'g_val =', g_val #print 'g_val =', g_val
...@@ -3283,7 +3284,7 @@ def test_make_vector(): ...@@ -3283,7 +3284,7 @@ def test_make_vector():
# The gradient should be 0 # The gradient should be 0
assert numpy.allclose(g_val, 0) assert numpy.allclose(g_val, 0)
else: else:
for var, grval in zip((b,i,d), g_val): for var, grval in zip((b, i, d), g_val):
float_inputs = [] float_inputs = []
if var.dtype.startswith('int'): if var.dtype.startswith('int'):
assert grval == 0 assert grval == 0
...@@ -3309,13 +3310,13 @@ def test_make_vector(): ...@@ -3309,13 +3310,13 @@ def test_make_vector():
utt.verify_grad(fun, [val[ri] for ri in float_inputs]) utt.verify_grad(fun, [val[ri] for ri in float_inputs])
#should fail #should fail
for (dtype,inputs) in [("int8",(b,i)), for (dtype, inputs) in [("int8", (b, i)),
("int8",(i,b)), ("int8", (i, b)),
("int8",(b,d)), ("int8", (b, d)),
("int8",(i,i)), ("int8", (i, i)),
("int32",(d,i)), ("int32", (d, i)),
("int32",(i,d)), ("int32", (i, d)),
("float32",(i,d)), ("float32", (i, d)),
]: ]:
try: try:
opt.MakeVector(dtype=dtype)(*inputs) opt.MakeVector(dtype=dtype)(*inputs)
...@@ -3337,7 +3338,7 @@ def test_local_join_1(): ...@@ -3337,7 +3338,7 @@ def test_local_join_1():
#test for matrix join(0,a) #test for matrix join(0,a)
a = tensor.matrix('a') a = tensor.matrix('a')
s = join(0,a) s = join(0, a)
f = function([a], s, mode=mode_opt) f = function([a], s, mode=mode_opt)
val = f([[1]]) val = f([[1]])
assert numpy.all(val == [[1]]) assert numpy.all(val == [[1]])
...@@ -3346,7 +3347,7 @@ def test_local_join_1(): ...@@ -3346,7 +3347,7 @@ def test_local_join_1():
assert f.maker.env.outputs[0].dtype == config.floatX assert f.maker.env.outputs[0].dtype == config.floatX
#test for matrix join(1,a) #test for matrix join(1,a)
s = join(1,a) s = join(1, a)
f = function([a], s, mode=mode_opt) f = function([a], s, mode=mode_opt)
val = f([[1]]) val = f([[1]])
assert numpy.all(val == [[1]]) assert numpy.all(val == [[1]])
...@@ -3355,7 +3356,7 @@ def test_local_join_1(): ...@@ -3355,7 +3356,7 @@ def test_local_join_1():
assert f.maker.env.outputs[0].dtype == config.floatX assert f.maker.env.outputs[0].dtype == config.floatX
#test we don't apply when their is 2 inputs #test we don't apply when their is 2 inputs
s = join(1,a,a) s = join(1, a, a)
f = function([a], s, mode=mode_opt) f = function([a], s, mode=mode_opt)
val = f([[1]]) val = f([[1]])
assert numpy.all(val == [[1]]) assert numpy.all(val == [[1]])
...@@ -3369,9 +3370,9 @@ def test_local_mul_to_neg(): ...@@ -3369,9 +3370,9 @@ def test_local_mul_to_neg():
Test that a multiplication by -1 or -1.0 yields the appropriate data type Test that a multiplication by -1 or -1.0 yields the appropriate data type
""" """
a = T.imatrix() a = T.imatrix()
f1 = theano.function([a], -1*a) f1 = theano.function([a], -1 * a)
f2 = theano.function([a], -1.0*a) f2 = theano.function([a], -1.0 * a)
aval = numpy.random.randint(0,10,(2,2)).astype('int32') aval = numpy.random.randint(0, 10, (2, 2)).astype('int32')
if config.cast_policy == 'custom': if config.cast_policy == 'custom':
assert f1(aval).dtype == a.dtype assert f1(aval).dtype == a.dtype
assert f2(aval).dtype == 'float64' assert f2(aval).dtype == 'float64'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论