提交 7e6a3dc5 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #4126 from olimastro/master

flake8 compile/tests/*.py
...@@ -4,7 +4,6 @@ from theano import config, shared ...@@ -4,7 +4,6 @@ from theano import config, shared
from theano.compile import function from theano.compile import function
from theano import tensor
from theano import tensor as T from theano import tensor as T
from theano.tensor.shared_randomstreams import RandomStreams from theano.tensor.shared_randomstreams import RandomStreams
...@@ -24,8 +23,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -24,8 +23,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX) xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3 yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX)*5 zv = numpy.ones((2, 2), dtype=config.floatX) * 5
# print function, function.__module__ # print function, function.__module__
# print fn.maker.fgraph.toposort() # print fn.maker.fgraph.toposort()
fn(xv, yv, zv) fn(xv, yv, zv)
...@@ -39,8 +38,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -39,8 +38,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
f = op(x, op(y, z)) f = op(x, op(y, z))
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = numpy.ones((2, 3), dtype=config.floatX) xv = numpy.ones((2, 3), dtype=config.floatX)
yv = numpy.ones((3, 4), dtype=config.floatX)*3 yv = numpy.ones((3, 4), dtype=config.floatX) * 3
zv = numpy.ones((4, 5), dtype=config.floatX)*5 zv = numpy.ones((4, 5), dtype=config.floatX) * 5
res = fn(xv, yv, zv) res = fn(xv, yv, zv)
assert res.shape == (2, 5) assert res.shape == (2, 5)
assert numpy.all(180.0 == res) assert numpy.all(180.0 == res)
...@@ -56,8 +55,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -56,8 +55,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
f = f - T.grad(T.sum(f), y) f = f - T.grad(T.sum(f), y)
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX) xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3 yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX)*5 zv = numpy.ones((2, 2), dtype=config.floatX) * 5
assert numpy.all(11.0 == fn(xv, yv, zv)) assert numpy.all(11.0 == fn(xv, yv, zv))
def test_grad_grad(self): def test_grad_grad(self):
...@@ -69,8 +68,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -69,8 +68,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
f = f - T.grad(T.sum(f), y) f = f - T.grad(T.sum(f), y)
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX) xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3 yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX)*5 zv = numpy.ones((2, 2), dtype=config.floatX) * 5
assert numpy.allclose(6.0, fn(xv, yv, zv)) assert numpy.allclose(6.0, fn(xv, yv, zv))
def test_shared(self): def test_shared(self):
...@@ -83,8 +82,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -83,8 +82,8 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = numpy.ones((2, 2), dtype=config.floatX) xv = numpy.ones((2, 2), dtype=config.floatX)
yv = numpy.ones((2, 2), dtype=config.floatX)*3 yv = numpy.ones((2, 2), dtype=config.floatX) * 3
zv = numpy.ones((2, 2), dtype=config.floatX)*5 zv = numpy.ones((2, 2), dtype=config.floatX) * 5
# print function, function.__module__ # print function, function.__module__
# print fn.maker.fgraph.toposort() # print fn.maker.fgraph.toposort()
assert numpy.allclose(8.0, fn(xv, yv, zv)) assert numpy.allclose(8.0, fn(xv, yv, zv))
...@@ -116,7 +115,7 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -116,7 +115,7 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
out1 = x * y out1 = x * y
out2 = y * z out2 = y * z
op1 = OpFromGraph([x ,y, z], [out1, out2]) op1 = OpFromGraph([x, y, z], [out1, out2])
results = op1.connection_pattern(None) results = op1.connection_pattern(None)
expect_result = [[True, False], expect_result = [[True, False],
[True, True], [True, True],
...@@ -139,7 +138,7 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -139,7 +138,7 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
# Inner graph where some computation doesn't rely on explicit inputs # Inner graph where some computation doesn't rely on explicit inputs
srng = RandomStreams(seed=234) srng = RandomStreams(seed=234)
rv_u = srng.uniform((2,2)) rv_u = srng.uniform((2, 2))
x, y = T.matrices('xy') x, y = T.matrices('xy')
out1 = x + rv_u out1 = x + rv_u
out2 = y + 3 out2 = y + 3
...@@ -155,14 +154,14 @@ class T_OpFromGraph(unittest_tools.InferShapeTester): ...@@ -155,14 +154,14 @@ class T_OpFromGraph(unittest_tools.InferShapeTester):
def test_infer_shape(self): def test_infer_shape(self):
x = T.matrix('x') x = T.matrix('x')
y = T.matrix('y') y = T.matrix('y')
o1 = x+y o1 = x + y
o2 = x*y o2 = x * y
op_graph = OpFromGraph([x,y], [o1,o2]) op_graph = OpFromGraph([x, y], [o1, o2])
q = T.matrix('q') q = T.matrix('q')
p = T.matrix('p') p = T.matrix('p')
self._compile_and_check([q,p], self._compile_and_check([q, p],
op_graph(q,p), op_graph(q, p),
[numpy.ones([3,4], dtype=config.floatX), [numpy.ones([3, 4], dtype=config.floatX),
numpy.ones([3,4], dtype=config.floatX)], numpy.ones([3, 4], dtype=config.floatX)],
OpFromGraph) OpFromGraph)
...@@ -160,16 +160,16 @@ class WeirdBrokenOp(gof.Op): ...@@ -160,16 +160,16 @@ class WeirdBrokenOp(gof.Op):
if self.behaviour == 'times2': if self.behaviour == 'times2':
behaviour = " Dz[m * Sz] = 2 * Da[m * Sa]; " behaviour = " Dz[m * Sz] = 2 * Da[m * Sa]; "
#out[0] = a * 2 # out[0] = a * 2
elif self.behaviour == 'times2_inplace': elif self.behaviour == 'times2_inplace':
#out[0] = a # out[0] = a
#out[0] *= 2 # out[0] *= 2
behaviour = " Dz[m * Sz] = 2 * Da[m * Sa]; " behaviour = " Dz[m * Sz] = 2 * Da[m * Sa]; "
elif self.behaviour == 'times1': elif self.behaviour == 'times1':
#out[0] = a * 1 # out[0] = a * 1
behaviour = " Dz[m * Sz] = Da[m * Sa]; " behaviour = " Dz[m * Sz] = Da[m * Sa]; "
elif self.behaviour == 'times1_inplace': elif self.behaviour == 'times1_inplace':
#out[0] = a # out[0] = a
behaviour = "" behaviour = ""
else: else:
raise ValueError(self.behaviour) raise ValueError(self.behaviour)
...@@ -189,7 +189,7 @@ wb1 = WeirdBrokenOp('times1') ...@@ -189,7 +189,7 @@ wb1 = WeirdBrokenOp('times1')
def test_badthunkoutput(): 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() a = theano.tensor.dvector()
b = theano.tensor.dvector() b = theano.tensor.dvector()
...@@ -525,7 +525,7 @@ class Test_ViewMap(unittest.TestCase): ...@@ -525,7 +525,7 @@ class Test_ViewMap(unittest.TestCase):
try: try:
f([1, 2, 3, 4], [5, 6, 7, 8]) f([1, 2, 3, 4], [5, 6, 7, 8])
assert False # DebugMode should have caught the error assert False # DebugMode should have caught the error
except debugmode.BadViewMap as e: except debugmode.BadViewMap:
# print e # print e
pass pass
...@@ -533,7 +533,7 @@ class Test_ViewMap(unittest.TestCase): ...@@ -533,7 +533,7 @@ class Test_ViewMap(unittest.TestCase):
# pretending that it is aliased to both the outputs. # pretending that it is aliased to both the outputs.
# This unfairly disables any destructive operations on the # This unfairly disables any destructive operations on the
# input, but guarantees correctness. # 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]) # f([1,2,3,4],[5,6,7,8])
...@@ -737,7 +737,7 @@ class Test_preallocated_output(unittest.TestCase): ...@@ -737,7 +737,7 @@ class Test_preallocated_output(unittest.TestCase):
check_preallocated_output=['c_contiguous']) check_preallocated_output=['c_contiguous'])
f = theano.function([a, b], out, mode=mode) f = theano.function([a, b], out, mode=mode)
out_val = f(a_val, b_val) f(a_val, b_val)
# print 'out_val =', out_val # print 'out_val =', out_val
# print out_val.strides # print out_val.strides
...@@ -769,7 +769,7 @@ class Test_preallocated_output(unittest.TestCase): ...@@ -769,7 +769,7 @@ class Test_preallocated_output(unittest.TestCase):
check_preallocated_output=['c_contiguous']) check_preallocated_output=['c_contiguous'])
f = theano.function([a, b], out, mode=mode) f = theano.function([a, b], out, mode=mode)
out_val = f(a_val, b_val) f(a_val, b_val)
# print 'out_val =', out_val # print 'out_val =', out_val
# print out_val.strides # print out_val.strides
......
import numpy, theano, unittest import numpy
import unittest
from theano.compile.pfunc import pfunc from theano.compile.pfunc import pfunc
from theano.compile.sharedvalue import shared from theano.compile.sharedvalue import shared
...@@ -56,5 +57,5 @@ class TestNnet(unittest.TestCase): ...@@ -56,5 +57,5 @@ class TestNnet(unittest.TestCase):
# print 'Mean cost at epoch %s: %s' % (epoch, mean_cost) # print 'Mean cost at epoch %s: %s' % (epoch, mean_cost)
self.assertTrue(abs(mean_cost - 0.20588975452) < 1e-6) self.assertTrue(abs(mean_cost - 0.20588975452) < 1e-6)
# Just call functions to make sure they do not crash. # Just call functions to make sure they do not crash.
out = nnet.compute_output(input) nnet.compute_output(input)
out = nnet.output_from_hidden(numpy.ones(10)) nnet.output_from_hidden(numpy.ones(10))
...@@ -75,7 +75,7 @@ def test_not_inplace(): ...@@ -75,7 +75,7 @@ def test_not_inplace():
x = theano.tensor.vector('x') x = theano.tensor.vector('x')
mode = theano.compile.MonitorMode(post_func=detect_nan) mode = theano.compile.MonitorMode(post_func=detect_nan)
#mode = mode.excluding('fusion', 'inplace') # mode = mode.excluding('fusion', 'inplace')
mode = mode.excluding('local_elemwise_fusion', mode = mode.excluding('local_elemwise_fusion',
'inplace_elemwise_optimizer') 'inplace_elemwise_optimizer')
o = theano.tensor.outer(x, x) o = theano.tensor.outer(x, x)
......
...@@ -8,8 +8,9 @@ from theano.tensor import dmatrix, iscalar, lscalar, dmatrices ...@@ -8,8 +8,9 @@ from theano.tensor import dmatrix, iscalar, lscalar, dmatrices
from theano import tensor from theano import tensor
from theano.compile import In from theano.compile import In
from theano.compile.sharedvalue import * from theano.compile import pfunc
from theano.compile.pfunc import * from theano.compile import shared
from theano.compile import config
def data_of(s): def data_of(s):
...@@ -712,7 +713,7 @@ class Test_aliasing_rules(unittest.TestCase): ...@@ -712,7 +713,7 @@ class Test_aliasing_rules(unittest.TestCase):
pass pass
from theano.sparse import enable_sparse from theano.sparse import enable_sparse
if enable_sparse == False: if not enable_sparse:
raise SkipTest('Optional package sparse disabled') raise SkipTest('Optional package sparse disabled')
from theano import sparse from theano import sparse
...@@ -816,9 +817,8 @@ class Test_aliasing_rules(unittest.TestCase): ...@@ -816,9 +817,8 @@ class Test_aliasing_rules(unittest.TestCase):
theano.In(m1, mutable=True), theano.In(m1, mutable=True),
theano.In(m2, mutable=True), theano.In(m2, mutable=True),
theano.In(m3, mutable=True)], theano.In(m3, mutable=True)],
(theano.dot((x * 2), m1) (theano.dot((x * 2), m1) + theano.dot((y * 3), m2) +
+ theano.dot((y * 3), m2) theano.dot((z * 4), m3)))
+ theano.dot((z * 4), m3)))
# Compute bogus values # Compute bogus values
v = numpy.asarray([1, 2, 3, 4, 5], dtype='float64') v = numpy.asarray([1, 2, 3, 4, 5], dtype='float64')
......
...@@ -44,7 +44,7 @@ class Test_profiling(unittest.TestCase): ...@@ -44,7 +44,7 @@ class Test_profiling(unittest.TestCase):
mode=m) mode=m)
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) f(*inp)
buf = StringIO() buf = StringIO()
f.profile.summary(buf) f.profile.summary(buf)
...@@ -72,7 +72,6 @@ class Test_profiling(unittest.TestCase): ...@@ -72,7 +72,6 @@ class Test_profiling(unittest.TestCase):
theano.config.profile_memory = config2 theano.config.profile_memory = config2
theano.config.profiling.min_peak_memory = config3 theano.config.profiling.min_peak_memory = config3
def test_ifelse(self): def test_ifelse(self):
config1 = theano.config.profile config1 = theano.config.profile
config2 = theano.config.profile_memory config2 = theano.config.profile_memory
...@@ -101,7 +100,7 @@ class Test_profiling(unittest.TestCase): ...@@ -101,7 +100,7 @@ class Test_profiling(unittest.TestCase):
big_mat1 = 10 big_mat1 = 10
big_mat2 = 11 big_mat2 = 11
out = f_ifelse(val1, val2, big_mat1, big_mat2) f_ifelse(val1, val2, big_mat1, big_mat2)
finally: finally:
theano.config.profile = config1 theano.config.profile = config1
......
...@@ -3,21 +3,15 @@ import unittest ...@@ -3,21 +3,15 @@ import unittest
import theano import theano
from theano.tensor import Tensor, TensorType from theano.tensor import Tensor, TensorType
from theano.compile.sharedvalue import * from theano.compile.sharedvalue import shared
from theano.compile.sharedvalue import SharedVariable
from theano.compile.sharedvalue import generic
class Test_SharedVariable(unittest.TestCase): class Test_SharedVariable(unittest.TestCase):
def test_ctors(self): def test_ctors(self):
if 0:
# when using an implementation that handles scalars with
# Scalar type
assert shared(7).type == Scalar('int64')
assert shared(7.0).type == Scalar('float64')
assert shared(7, dtype='float64').type == Scalar('float64')
else:
if theano.configdefaults.python_int_bitwidth() == 32: if theano.configdefaults.python_int_bitwidth() == 32:
assert shared(7).type == theano.tensor.iscalar, shared(7).type assert shared(7).type == theano.tensor.iscalar, shared(7).type
else: else:
...@@ -31,8 +25,7 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -31,8 +25,7 @@ class Test_SharedVariable(unittest.TestCase):
b = shared(numpy.random.rand(4, 5)) b = shared(numpy.random.rand(4, 5))
assert b.type == TensorType('float64', broadcastable=[False, False]) assert b.type == TensorType('float64', broadcastable=[False, False])
b = shared(numpy.random.rand(5, 1, 2)) b = shared(numpy.random.rand(5, 1, 2))
assert b.type == TensorType('float64', assert b.type == TensorType('float64', broadcastable=[False, False, False])
broadcastable=[False, False, False])
assert shared([]).type == generic assert shared([]).type == generic
......
...@@ -30,15 +30,6 @@ whitelist_flake8 = [ ...@@ -30,15 +30,6 @@ whitelist_flake8 = [
"tests/__init__.py", "tests/__init__.py",
"compile/__init__.py", "compile/__init__.py",
"compile/profiling.py", "compile/profiling.py",
"compile/tests/test_builders.py",
"compile/tests/test_misc.py",
"compile/tests/test_monitormode.py",
"compile/tests/test_function_module.py",
"compile/tests/test_shared.py",
"compile/tests/test_ops.py",
"compile/tests/test_pfunc.py",
"compile/tests/test_debugmode.py",
"compile/tests/test_profiling.py",
"typed_list/__init__.py", "typed_list/__init__.py",
"tensor/__init__.py", "tensor/__init__.py",
"tensor/tests/test_subtensor.py", "tensor/tests/test_subtensor.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论