提交 0b5dbed9 authored 作者: Olivier Mastropietro's avatar Olivier Mastropietro

Fixed the PEP8 Error. Modified some tests to meet the standards without changing the output

上级 0aa5ff77
......@@ -4,7 +4,6 @@ from theano import config, shared
from theano.compile import function
from theano import tensor
from theano import tensor as T
from theano.tensor.shared_randomstreams import RandomStreams
......@@ -24,8 +23,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3
zv = numpy.ones((2, 2), dtype=config.floatX)*5
yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX) * 5
# print function, function.__module__
# print fn.maker.fgraph.toposort()
fn(xv, yv, zv)
......@@ -39,8 +38,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
f = op(x, op(y, z))
fn = function([x, y, z], f)
xv = numpy.ones((2, 3), dtype=config.floatX)
yv = numpy.ones((3, 4), dtype=config.floatX)*3
zv = numpy.ones((4, 5), dtype=config.floatX)*5
yv = numpy.ones((3, 4), dtype=config.floatX) * 3
zv = numpy.ones((4, 5), dtype=config.floatX) * 5
res = fn(xv, yv, zv)
assert res.shape == (2, 5)
assert numpy.all(180.0 == res)
......@@ -56,8 +55,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
f = f - T.grad(T.sum(f), y)
fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3
zv = numpy.ones((2, 2), dtype=config.floatX)*5
yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX) * 5
assert numpy.all(11.0 == fn(xv, yv, zv))
def test_grad_grad(self):
......@@ -69,8 +68,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
f = f - T.grad(T.sum(f), y)
fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3
zv = numpy.ones((2, 2), dtype=config.floatX)*5
yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX) * 5
assert numpy.allclose(6.0, fn(xv, yv, zv))
def test_shared(self):
......@@ -83,8 +82,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3
zv = numpy.ones((2, 2), dtype=config.floatX)*5
yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX) * 5
# print function, function.__module__
# print fn.maker.fgraph.toposort()
assert numpy.allclose(8.0, fn(xv, yv, zv))
......@@ -116,7 +115,7 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
out1 = x * y
out2 = y * z
op1 = OpFromGraph([x ,y, z], [out1, out2])
op1 = OpFromGraph([x, y, z], [out1, out2])
results = op1.connection_pattern(None)
expect_result = [[True, False],
[True, True],
......@@ -139,7 +138,7 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
# Inner graph where some computation doesn't rely on explicit inputs
srng = RandomStreams(seed=234)
rv_u = srng.uniform((2,2))
rv_u = srng.uniform((2, 2))
x, y = T.matrices('xy')
out1 = x + rv_u
out2 = y + 3
......@@ -155,14 +154,14 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
def test_infer_shape(self):
x = T.matrix('x')
y = T.matrix('y')
o1 = x+y
o2 = x*y
op_graph = OpFromGraph([x,y], [o1,o2])
o1 = x + y
o2 = x * y
op_graph = OpFromGraph([x, y], [o1, o2])
q = T.matrix('q')
p = T.matrix('p')
self._compile_and_check([q,p],
op_graph(q,p),
[numpy.ones([3,4], dtype=config.floatX),
numpy.ones([3,4], dtype=config.floatX)],
self._compile_and_check([q, p],
op_graph(q, p),
[numpy.ones([3, 4], dtype=config.floatX),
numpy.ones([3, 4], dtype=config.floatX)],
OpFromGraph)
......@@ -160,16 +160,16 @@ class WeirdBrokenOp(gof.Op):
if self.behaviour == 'times2':
behaviour = " Dz[m * Sz] = 2 * Da[m * Sa]; "
#out[0] = a * 2
# out[0] = a * 2
elif self.behaviour == 'times2_inplace':
#out[0] = a
#out[0] *= 2
# out[0] = a
# out[0] *= 2
behaviour = " Dz[m * Sz] = 2 * Da[m * Sa]; "
elif self.behaviour == 'times1':
#out[0] = a * 1
# out[0] = a * 1
behaviour = " Dz[m * Sz] = Da[m * Sa]; "
elif self.behaviour == 'times1_inplace':
#out[0] = a
# out[0] = a
behaviour = ""
else:
raise ValueError(self.behaviour)
......@@ -189,7 +189,7 @@ wb1 = WeirdBrokenOp('times1')
def test_badthunkoutput():
# Check if the c and python code is consistent.
# Check if the c and python code is consistent.
a = theano.tensor.dvector()
b = theano.tensor.dvector()
......@@ -533,7 +533,7 @@ class Test_ViewMap(unittest.TestCase):
# pretending that it is aliased to both the outputs.
# This unfairly disables any destructive operations on the
# input, but guarantees correctness.
#custom_op.view_map = {0:[0], 1:[1]}
# custom_op.view_map = {0:[0], 1:[1]}
# f([1,2,3,4],[5,6,7,8])
......@@ -737,7 +737,7 @@ class Test_preallocated_output(unittest.TestCase):
check_preallocated_output=['c_contiguous'])
f = theano.function([a, b], out, mode=mode)
out_val = f(a_val, b_val)
# out_val = f(a_val, b_val)
# print 'out_val =', out_val
# print out_val.strides
......@@ -769,7 +769,7 @@ class Test_preallocated_output(unittest.TestCase):
check_preallocated_output=['c_contiguous'])
f = theano.function([a, b], out, mode=mode)
out_val = f(a_val, b_val)
# out_val = f(a_val, b_val)
# print 'out_val =', out_val
# print out_val.strides
......
import numpy, theano, unittest
import numpy
import unittest
from theano.compile.pfunc import pfunc
from theano.compile.sharedvalue import shared
......@@ -56,5 +57,7 @@ class TestNnet(unittest.TestCase):
# print 'Mean cost at epoch %s: %s' % (epoch, mean_cost)
self.assertTrue(abs(mean_cost - 0.20588975452) < 1e-6)
# Just call functions to make sure they do not crash.
out = nnet.compute_output(input)
out = nnet.output_from_hidden(numpy.ones(10))
# out = nnet.compute_output(input)
# out = nnet.output_from_hidden(numpy.ones(10))
nnet.compute_output(input)
nnet.output_from_hidden(numpy.ones(10))
......@@ -75,7 +75,7 @@ def test_not_inplace():
x = theano.tensor.vector('x')
mode = theano.compile.MonitorMode(post_func=detect_nan)
#mode = mode.excluding('fusion', 'inplace')
# mode = mode.excluding('fusion', 'inplace')
mode = mode.excluding('local_elemwise_fusion',
'inplace_elemwise_optimizer')
o = theano.tensor.outer(x, x)
......
......@@ -712,7 +712,7 @@ class Test_aliasing_rules(unittest.TestCase):
pass
from theano.sparse import enable_sparse
if enable_sparse == False:
if not enable_sparse:
raise SkipTest('Optional package sparse disabled')
from theano import sparse
......@@ -816,9 +816,9 @@ class Test_aliasing_rules(unittest.TestCase):
theano.In(m1, mutable=True),
theano.In(m2, mutable=True),
theano.In(m3, mutable=True)],
(theano.dot((x * 2), m1)
+ theano.dot((y * 3), m2)
+ theano.dot((z * 4), m3)))
(theano.dot((x * 2), m1) +
theano.dot((y * 3), m2) +
theano.dot((z * 4), m3)))
# Compute bogus values
v = numpy.asarray([1, 2, 3, 4, 5], dtype='float64')
......
......@@ -44,7 +44,7 @@ class Test_profiling(unittest.TestCase):
mode=m)
inp = [numpy.arange(1024, dtype='float32') + 1 for i in range(len(x))]
output = f(*inp)
f(*inp)
buf = StringIO()
f.profile.summary(buf)
......@@ -72,7 +72,6 @@ class Test_profiling(unittest.TestCase):
theano.config.profile_memory = config2
theano.config.profiling.min_peak_memory = config3
def test_ifelse(self):
config1 = theano.config.profile
config2 = theano.config.profile_memory
......@@ -101,7 +100,8 @@ class Test_profiling(unittest.TestCase):
big_mat1 = 10
big_mat2 = 11
out = f_ifelse(val1, val2, big_mat1, big_mat2)
# out = f_ifelse(val1, val2, big_mat1, big_mat2)
f_ifelse(val1, val2, big_mat1, big_mat2)
finally:
theano.config.profile = config1
......
......@@ -31,8 +31,7 @@ class Test_SharedVariable(unittest.TestCase):
b = shared(numpy.random.rand(4, 5))
assert b.type == TensorType('float64', broadcastable=[False, False])
b = shared(numpy.random.rand(5, 1, 2))
assert b.type == TensorType('float64',
broadcastable=[False, False, False])
assert b.type == TensorType('float64', broadcastable=[False, False, False])
assert shared([]).type == generic
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论