提交 201b8102 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

fixed a bunch more things autopep8 broke

上级 3c015aca
...@@ -4960,8 +4960,8 @@ class TestARange(unittest.TestCase): ...@@ -4960,8 +4960,8 @@ class TestARange(unittest.TestCase):
assert arange(iscalar(), dscalar()).dtype == dscalar().dtype assert arange(iscalar(), dscalar()).dtype == dscalar().dtype
assert arange(fscalar(), dscalar()).dtype == dscalar().dtype assert arange(fscalar(), dscalar()).dtype == dscalar().dtype
assert arange(iscalar(), fscalar(), dscalar()) assert arange(iscalar(), fscalar(), dscalar()).dtype == \
.dtype == dscalar().dtype dscalar().dtype
elif config.cast_policy in ('numpy', 'numpy+floatX'): elif config.cast_policy in ('numpy', 'numpy+floatX'):
for dtype in get_numeric_types(): for dtype in get_numeric_types():
# Test with a single argument. # Test with a single argument.
...@@ -5612,10 +5612,10 @@ def _test_autocast_custom(): ...@@ -5612,10 +5612,10 @@ def _test_autocast_custom():
ac.__enter__() ac.__enter__()
assert (dvector() + 1.1).dtype == 'float64' assert (dvector() + 1.1).dtype == 'float64'
assert (fvector() + 1.1).dtype == 'float32' assert (fvector() + 1.1).dtype == 'float32'
assert (fvector() + theano._asarray(1.1, dtype='float64')) assert (fvector() + theano._asarray(1.1, dtype='float64')).dtype == \
.dtype == 'float64' 'float64'
assert (fvector() + theano._asarray(1.1, dtype='float32')) assert (fvector() + theano._asarray(1.1, dtype='float32')).dtype == \
.dtype == 'float32' 'float32'
assert (dvector() + 1).dtype == 'float64' assert (dvector() + 1).dtype == 'float64'
assert (fvector() + 1).dtype == 'float32' assert (fvector() + 1).dtype == 'float32'
...@@ -5629,10 +5629,10 @@ def _test_autocast_custom(): ...@@ -5629,10 +5629,10 @@ def _test_autocast_custom():
assert (dvector() + 1.1).dtype == 'float64' assert (dvector() + 1.1).dtype == 'float64'
assert (fvector() + 1.1).dtype == 'float64' assert (fvector() + 1.1).dtype == 'float64'
assert (fvector() + 1.0).dtype == 'float64' assert (fvector() + 1.0).dtype == 'float64'
assert (fvector() + theano._asarray(1.1, dtype='float64')) assert (fvector() + theano._asarray(1.1, dtype='float64')).dtype == \
.dtype == 'float64' 'float64'
assert (fvector() + theano._asarray(1.1, dtype='float32')) assert (fvector() + theano._asarray(1.1, dtype='float32')).dtype == \
.dtype == 'float32' 'float32'
assert (dvector() + 1).dtype == 'float64' assert (dvector() + 1).dtype == 'float64'
assert (fvector() + 1).dtype == 'float32' assert (fvector() + 1).dtype == 'float32'
...@@ -5981,8 +5981,8 @@ def test_mod(): ...@@ -5981,8 +5981,8 @@ def test_mod():
as Python. That is what we want. as Python. That is what we want.
""" """
x, y = fscalars('xy') x, y = fscalars('xy')
fn = gof.DualLinker().accept(gof.FunctionGraph([x, y], [x % y])) fn = gof.DualLinker().accept(
.make_function() gof.FunctionGraph([x, y], [x % y])).make_function()
for a, b in ((0, 1), (1, 1), (0, -1), (1, -1), (-1, -1), for a, b in ((0, 1), (1, 1), (0, -1), (1, -1), (-1, -1),
(1, 2), (-1, 2), (1, -2), (-1, -2), (1, 2), (-1, 2), (1, -2), (-1, -2),
(5, 3), (-5, 3), (5, -3), (-5, -3) (5, 3), (-5, 3), (5, -3), (-5, -3)
......
...@@ -631,11 +631,11 @@ class test_canonize(unittest.TestCase): ...@@ -631,11 +631,11 @@ class test_canonize(unittest.TestCase):
a = T.abs_(x) a = T.abs_(x)
if theano.config.mode == 'FAST_COMPILE': if theano.config.mode == 'FAST_COMPILE':
mode = theano.compile.mode.get_mode('FAST_RUN') mode = theano.compile.mode.get_mode('FAST_RUN').excluding(
.excluding("local_elemwise_fusion") "local_elemwise_fusion")
else: else:
mode = theano.compile.mode.get_default_mode() mode = theano.compile.mode.get_default_mode().excluding(
.excluding("local_elemwise_fusion") "local_elemwise_fusion")
f = theano.function([x], [(4 * x) / abs(2 * x)], mode=mode) f = theano.function([x], [(4 * x) / abs(2 * x)], mode=mode)
print f.maker.fgraph.toposort() print f.maker.fgraph.toposort()
...@@ -1106,11 +1106,11 @@ class test_fusion(unittest.TestCase): ...@@ -1106,11 +1106,11 @@ class test_fusion(unittest.TestCase):
shp = (5, 5) shp = (5, 5)
#we need the optimisation enabled, debug do this. #we need the optimisation enabled, debug do this.
if theano.config.mode == "FAST_COMPILE": if theano.config.mode == "FAST_COMPILE":
mode = theano.compile.mode.get_mode("FAST_RUN") mode = theano.compile.mode.get_mode("FAST_RUN").including(
.including('local_elemwise_fusion', 'canonicalize', 'gpu') 'local_elemwise_fusion', 'canonicalize', 'gpu')
else: else:
mode = theano.compile.mode.get_default_mode() mode = theano.compile.mode.get_default_mode().including(
.including('local_elemwise_fusion', 'canonicalize', 'gpu') 'local_elemwise_fusion', 'canonicalize', 'gpu')
import theano.sandbox.cuda as cuda import theano.sandbox.cuda as cuda
if not cuda.cuda_available: if not cuda.cuda_available:
raise SkipTest("cuda not available") raise SkipTest("cuda not available")
...@@ -1120,11 +1120,11 @@ class test_fusion(unittest.TestCase): ...@@ -1120,11 +1120,11 @@ class test_fusion(unittest.TestCase):
def test_gpu_fusion_Xd(self): def test_gpu_fusion_Xd(self):
#we need the optimisation enabled, debug do this. #we need the optimisation enabled, debug do this.
if theano.config.mode == "FAST_COMPILE": if theano.config.mode == "FAST_COMPILE":
mode = theano.compile.mode.get_mode("FAST_RUN") mode = theano.compile.mode.get_mode("FAST_RUN").including(
.including('local_elemwise_fusion', 'canonicalize', 'gpu') 'local_elemwise_fusion', 'canonicalize', 'gpu')
else: else:
mode = theano.compile.mode.get_default_mode() mode = theano.compile.mode.get_default_mode().including(
.including('local_elemwise_fusion', 'canonicalize', 'gpu') 'local_elemwise_fusion', 'canonicalize', 'gpu')
import theano.sandbox.cuda as cuda import theano.sandbox.cuda as cuda
if not cuda.cuda_available: if not cuda.cuda_available:
raise SkipTest("cuda not available") raise SkipTest("cuda not available")
...@@ -1166,7 +1166,7 @@ class test_fusion(unittest.TestCase): ...@@ -1166,7 +1166,7 @@ class test_fusion(unittest.TestCase):
print "times2/times1" print "times2/times1"
print d print d
print "min", d.min(), "argmin", d.argmin(), "max", d.max(), print "min", d.min(), "argmin", d.argmin(), "max", d.max(), \
"mean", d.mean(), "std", d.std() "mean", d.mean(), "std", d.std()
def test_fusion_inplace(self): def test_fusion_inplace(self):
...@@ -1272,8 +1272,8 @@ class test_fusion(unittest.TestCase): ...@@ -1272,8 +1272,8 @@ class test_fusion(unittest.TestCase):
for x in ndl: for x in ndl:
cmp = not isinstance(x, list) cmp = not isinstance(x, list)
if not cmp and x: if not cmp and x:
cmp = x[0] cmp = x[0].__class__.__name__ != \
.__class__.__name__ != 'array_converter' 'array_converter'
if cmp: if cmp:
cmp = x[0] != 'Option' cmp = x[0] != 'Option'
if cmp: if cmp:
...@@ -2946,8 +2946,8 @@ def test_constant_get_stabilized(): ...@@ -2946,8 +2946,8 @@ def test_constant_get_stabilized():
f2 = theano.function([x2], y2) f2 = theano.function([x2], y2)
try: try:
assert len(f2.maker.fgraph.toposort()) == 1 assert len(f2.maker.fgraph.toposort()) == 1
assert f2.maker.fgraph.toposort()[0] assert f2.maker.fgraph.toposort()[0].op == \
.op == theano.tensor.nnet.sigm.softplus theano.tensor.nnet.sigm.softplus
assert f2(800) == 800 assert f2(800) == 800
x = T.as_tensor_variable(800) x = T.as_tensor_variable(800)
...@@ -2985,8 +2985,8 @@ class T_local_switch_sink(unittest.TestCase): ...@@ -2985,8 +2985,8 @@ class T_local_switch_sink(unittest.TestCase):
[[numpy.asarray(1.0),numpy.asarray( [[numpy.asarray(1.0),numpy.asarray(
0.0),numpy.asarray(1.0),numpy.asarray(0.0)]] 0.0),numpy.asarray(1.0),numpy.asarray(0.0)]]
self.mode = theano.compile.mode.get_default_mode() self.mode = theano.compile.mode.get_default_mode().including(
.including('canonicalize', 'fast_run').excluding('gpu', 'fusion') 'canonicalize', 'fast_run').excluding('gpu', 'fusion')
self.mode = copy.copy(self.mode) self.mode = copy.copy(self.mode)
self.mode.check_isfinite = False self.mode.check_isfinite = False
...@@ -3033,8 +3033,8 @@ class T_local_switch_sink(unittest.TestCase): ...@@ -3033,8 +3033,8 @@ class T_local_switch_sink(unittest.TestCase):
class T_local_erf(unittest.TestCase): class T_local_erf(unittest.TestCase):
def setUp(self): def setUp(self):
self.mode = theano.compile.mode.get_default_mode() self.mode = theano.compile.mode.get_default_mode().including(
.including('canonicalize', 'fast_run').excluding('gpu', 'fusion') 'canonicalize', 'fast_run').excluding('gpu', 'fusion')
self.mode._optimizer.position_cutoff = 1.50001 self.mode._optimizer.position_cutoff = 1.50001
def test_local_one_plus_erf(self): def test_local_one_plus_erf(self):
...@@ -3070,19 +3070,19 @@ class T_local_erf(unittest.TestCase): ...@@ -3070,19 +3070,19 @@ class T_local_erf(unittest.TestCase):
f = theano.function([x], 1 - T.erf(x), mode=self.mode) f = theano.function([x], 1 - T.erf(x), mode=self.mode)
print f.maker.fgraph.toposort() print f.maker.fgraph.toposort()
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erfc] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erfc]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
f = theano.function([x], 1 + (-T.erf(x)), mode=self.mode) f = theano.function([x], 1 + (-T.erf(x)), mode=self.mode)
print f.maker.fgraph.toposort() print f.maker.fgraph.toposort()
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erfc] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erfc]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
f = theano.function([x], (-T.erf(x)) + 1, mode=self.mode) f = theano.function([x], (-T.erf(x)) + 1, mode=self.mode)
print f.maker.fgraph.toposort() print f.maker.fgraph.toposort()
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erfc] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erfc]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
...@@ -3092,7 +3092,7 @@ class T_local_erf(unittest.TestCase): ...@@ -3092,7 +3092,7 @@ class T_local_erf(unittest.TestCase):
assert len(topo) == 2, f.maker.fgraph.toposort() assert len(topo) == 2, f.maker.fgraph.toposort()
assert topo[0].op == T.erf, f.maker.fgraph.toposort() assert topo[0].op == T.erf, f.maker.fgraph.toposort()
assert isinstance(topo[1].op, T.Elemwise), f.maker.fgraph.toposort() assert isinstance(topo[1].op, T.Elemwise), f.maker.fgraph.toposort()
assert isinstance(topo[1].op.scalar_op, scal.Add) assert isinstance(topo[1].op.scalar_op, scal.Add)\
or isinstance(topo[1].op.scalar_op,scal.Sub), f.maker.fgraph.toposort() or isinstance(topo[1].op.scalar_op,scal.Sub), f.maker.fgraph.toposort()
print f(val) print f(val)
...@@ -3122,15 +3122,15 @@ class T_local_erf(unittest.TestCase): ...@@ -3122,15 +3122,15 @@ class T_local_erf(unittest.TestCase):
assert len(topo) == 2 assert len(topo) == 2
assert topo[0].op == T.erf assert topo[0].op == T.erf
assert isinstance(topo[1].op, T.Elemwise) assert isinstance(topo[1].op, T.Elemwise)
assert isinstance(topo[1].op.scalar_op, scal.Add) assert isinstance(topo[1].op.scalar_op, scal.Add)\
or isinstance(topo[1].op.scalar_op, scal.Sub) or isinstance(topo[1].op.scalar_op, scal.Sub)
print f(val) print f(val)
class T_local_erfc(unittest.TestCase): class T_local_erfc(unittest.TestCase):
def setUp(self): def setUp(self):
self.mode_fusion = theano.compile.mode.get_default_mode() self.mode_fusion = theano.compile.mode.get_default_mode().including(
.including('canonicalize').including('fast_run').excluding('gpu') 'canonicalize').including('fast_run').excluding('gpu')
self.mode = self.mode_fusion.excluding('fusion') self.mode = self.mode_fusion.excluding('fusion')
self.mode._optimizer.position_cutoff = 1.50001 self.mode._optimizer.position_cutoff = 1.50001
...@@ -3143,13 +3143,13 @@ class T_local_erfc(unittest.TestCase): ...@@ -3143,13 +3143,13 @@ class T_local_erfc(unittest.TestCase):
f = theano.function([x], 1 - T.erfc(x), mode=self.mode) f = theano.function([x], 1 - T.erfc(x), mode=self.mode)
theano.printing.debugprint(f) theano.printing.debugprint(f)
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
f = theano.function([x], (-T.erfc(x)) + 1, mode=self.mode) f = theano.function([x], (-T.erfc(x)) + 1, mode=self.mode)
theano.printing.debugprint(f) theano.printing.debugprint(f)
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
...@@ -3159,7 +3159,7 @@ class T_local_erfc(unittest.TestCase): ...@@ -3159,7 +3159,7 @@ class T_local_erfc(unittest.TestCase):
assert len(topo) == 2, f.maker.fgraph.toposort() assert len(topo) == 2, f.maker.fgraph.toposort()
assert topo[0].op == T.erfc, f.maker.fgraph.toposort() assert topo[0].op == T.erfc, f.maker.fgraph.toposort()
assert isinstance(topo[1].op, T.Elemwise), f.maker.fgraph.toposort() assert isinstance(topo[1].op, T.Elemwise), f.maker.fgraph.toposort()
assert isinstance(topo[1].op.scalar_op, scal.Sub) assert isinstance(topo[1].op.scalar_op, scal.Sub)\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
...@@ -3171,19 +3171,19 @@ class T_local_erfc(unittest.TestCase): ...@@ -3171,19 +3171,19 @@ class T_local_erfc(unittest.TestCase):
f = theano.function([x], -1 + T.erfc(-x), mode=self.mode) f = theano.function([x], -1 + T.erfc(-x), mode=self.mode)
theano.printing.debugprint(f) theano.printing.debugprint(f)
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
f = theano.function([x], T.erfc(-x) - 1, mode=self.mode) f = theano.function([x], T.erfc(-x) - 1, mode=self.mode)
theano.printing.debugprint(f) theano.printing.debugprint(f)
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
f = theano.function([x], T.erfc(-x) + (-1), mode=self.mode) f = theano.function([x], T.erfc(-x) + (-1), mode=self.mode)
theano.printing.debugprint(f) theano.printing.debugprint(f)
assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf] assert [n.op for n in f.maker.fgraph.toposort()] == [T.erf]\
, f.maker.fgraph.toposort() , f.maker.fgraph.toposort()
print f(val) print f(val)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论