提交 77c20a3b authored 作者: David Warde-Farley's avatar David Warde-Farley

Another whitespace cleanup.

上级 8bad060c
...@@ -36,7 +36,7 @@ class BROKEN_ON_PURPOSE_Add(gof.Op): ...@@ -36,7 +36,7 @@ class BROKEN_ON_PURPOSE_Add(gof.Op):
#ERROR TO ADD THIS CRAPPY OFFSET #ERROR TO ADD THIS CRAPPY OFFSET
if self.py_offset: if self.py_offset:
out[0] = z+0.5 out[0] = z+0.5
else: out[0] = z else: out[0] = z
def c_code(self, node, name, (a, b), (z,), sub): def c_code(self, node, name, (a, b), (z,), sub):
return """ return """
...@@ -75,7 +75,7 @@ class BROKEN_ON_PURPOSE_Add(gof.Op): ...@@ -75,7 +75,7 @@ class BROKEN_ON_PURPOSE_Add(gof.Op):
# inconsistent is a invalid op, whose perform and c_code do not match # inconsistent is a invalid op, whose perform and c_code do not match
inconsistent = BROKEN_ON_PURPOSE_Add(False) inconsistent = BROKEN_ON_PURPOSE_Add(False)
# off_by_half is a good op, that is different from theano.sparse.sd_csc # off_by_half is a good op, that is different from theano.sparse.sd_csc
off_by_half = BROKEN_ON_PURPOSE_Add(True) off_by_half = BROKEN_ON_PURPOSE_Add(True)
class WeirdBrokenOp(gof.Op): class WeirdBrokenOp(gof.Op):
""" """
...@@ -172,11 +172,11 @@ def test_badclinkeroutput(): ...@@ -172,11 +172,11 @@ def test_badclinkeroutput():
a = theano.tensor.dvector() a = theano.tensor.dvector()
b = theano.tensor.dvector() b = theano.tensor.dvector()
f_good = theano.function([a, b], f_good = theano.function([a, b],
off_by_half(a, b), off_by_half(a, b),
mode=debugmode.DebugMode(check_c_code=True)) mode=debugmode.DebugMode(check_c_code=True))
f_inconsistent = theano.function([a,b], f_inconsistent = theano.function([a,b],
inconsistent(a, b), inconsistent(a, b),
mode=debugmode.DebugMode(check_c_code=True)) mode=debugmode.DebugMode(check_c_code=True))
#this should evaluate with no error #this should evaluate with no error
...@@ -189,7 +189,7 @@ def test_badclinkeroutput(): ...@@ -189,7 +189,7 @@ def test_badclinkeroutput():
return #TEST PASS return #TEST PASS
assert False #an error should have been detected assert False #an error should have been detected
def test_badoptimization(): def test_badoptimization():
@gof.local_optimizer([theano.tensor.add]) @gof.local_optimizer([theano.tensor.add])
...@@ -204,7 +204,7 @@ def test_badoptimization(): ...@@ -204,7 +204,7 @@ def test_badoptimization():
a = theano.tensor.dvector() a = theano.tensor.dvector()
b = theano.tensor.dvector() b = theano.tensor.dvector()
f = theano.function([a, b], a+b, f = theano.function([a, b], a+b,
mode=debugmode.DebugMode(optimizer=opt, check_c_code=True)) mode=debugmode.DebugMode(optimizer=opt, check_c_code=True))
try: try:
...@@ -235,8 +235,8 @@ def test_stochasticoptimization(): ...@@ -235,8 +235,8 @@ def test_stochasticoptimization():
b = theano.tensor.dvector() b = theano.tensor.dvector()
try: try:
f = theano.function([a, b], f = theano.function([a, b],
theano.tensor.add(a, b), theano.tensor.add(a, b),
mode=debugmode.DebugMode(optimizer=opt, check_c_code=True)) mode=debugmode.DebugMode(optimizer=opt, check_c_code=True))
except debugmode.StochasticOrder: except debugmode.StochasticOrder:
return #TEST PASS return #TEST PASS
......
...@@ -73,7 +73,7 @@ class TanhRnn(Op): ...@@ -73,7 +73,7 @@ class TanhRnn(Op):
This class implements the recurrent part of a recurrent neural network. This class implements the recurrent part of a recurrent neural network.
There is not a neat way to include this in a more fine-grained way in Theano at the moment, There is not a neat way to include this in a more fine-grained way in Theano at the moment,
so to get something working, I'm implementing a relatively complicated Op that could be so to get something working, I'm implementing a relatively complicated Op that could be
broken down later into constituents. broken down later into constituents.
Anyway, this Op implements recursive computation of the form: Anyway, this Op implements recursive computation of the form:
...@@ -81,7 +81,7 @@ class TanhRnn(Op): ...@@ -81,7 +81,7 @@ class TanhRnn(Op):
.. latex-eqn: .. latex-eqn:
z_t &= \tanh( z_{t-1} A + x_{t-1}) z_t &= \tanh( z_{t-1} A + x_{t-1})
For z0 a vector, and x a TxM matrix, it returns a matrix z of shape (T+1, M), For z0 a vector, and x a TxM matrix, it returns a matrix z of shape (T+1, M),
in which z[0] = z0. in which z[0] = z0.
""" """
...@@ -275,7 +275,7 @@ def test_WEIRD_STUFF(): ...@@ -275,7 +275,7 @@ def test_WEIRD_STUFF():
print rnn1.minimizer.step.maker.inputs print rnn1.minimizer.step.maker.inputs
print rnn2.minimizer.step.maker.inputs print rnn2.minimizer.step.maker.inputs
# for i in range(1,len(rnn1.minimizer.step.maker.inputs)): # for i in range(1,len(rnn1.minimizer.step.maker.inputs)):
# print "valid update:",theano.printing.pp(rnn1.minimizer.step.maker.inputs[i].update), # print "valid update:",theano.printing.pp(rnn1.minimizer.step.maker.inputs[i].update),
...@@ -284,7 +284,7 @@ def test_WEIRD_STUFF(): ...@@ -284,7 +284,7 @@ def test_WEIRD_STUFF():
# print rnn2.minimizer.step.maker.inputs[i].update.name # print rnn2.minimizer.step.maker.inputs[i].update.name
# print dir(rnn1.minimizer.step.maker.inputs[5].update) # print dir(rnn1.minimizer.step.maker.inputs[5].update)
# print dir(rnn2.minimizer.step.maker.inputs[5].update) # print dir(rnn2.minimizer.step.maker.inputs[5].update)
niter=3 niter=3
......
...@@ -24,7 +24,7 @@ class TDouble(Type): ...@@ -24,7 +24,7 @@ class TDouble(Type):
return """ return """
%(name)s = 0; %(name)s = 0;
%(name)s_bad_thing = malloc(100000); %(name)s_bad_thing = malloc(100000);
//printf("Initializing %(name)s\\n"); //printf("Initializing %(name)s\\n");
""" % locals() """ % locals()
def c_literal(self, data): def c_literal(self, data):
...@@ -40,7 +40,7 @@ class TDouble(Type): ...@@ -40,7 +40,7 @@ class TDouble(Type):
%(name)s_bad_thing = NULL; %(name)s_bad_thing = NULL;
//printf("Extracting %(name)s\\n"); //printf("Extracting %(name)s\\n");
""" % dict(locals(), **sub) """ % dict(locals(), **sub)
def c_sync(self, name, sub): def c_sync(self, name, sub):
return """ return """
Py_XDECREF(py_%(name)s); Py_XDECREF(py_%(name)s);
...@@ -71,7 +71,7 @@ class MyOp(Op): ...@@ -71,7 +71,7 @@ class MyOp(Op):
def __init__(self, nin, name): def __init__(self, nin, name):
self.nin = nin self.nin = nin
self.name = name self.name = name
def make_node(self, *inputs): def make_node(self, *inputs):
assert len(inputs) == self.nin assert len(inputs) == self.nin
inputs = map(as_variable, inputs) inputs = map(as_variable, inputs)
...@@ -98,28 +98,28 @@ class Binary(MyOp): ...@@ -98,28 +98,28 @@ class Binary(MyOp):
def __init__(self): def __init__(self):
MyOp.__init__(self, 2, self.__class__.__name__) MyOp.__init__(self, 2, self.__class__.__name__)
class Add(Binary): class Add(Binary):
def c_code(self, node, name, (x, y), (z, ), sub): def c_code(self, node, name, (x, y), (z, ), sub):
return "%(z)s = %(x)s + %(y)s;" % locals() return "%(z)s = %(x)s + %(y)s;" % locals()
def impl(self, x, y): def impl(self, x, y):
return x + y return x + y
add = Add() add = Add()
class Sub(Binary): class Sub(Binary):
def c_code(self, node, name, (x, y), (z, ), sub): def c_code(self, node, name, (x, y), (z, ), sub):
return "%(z)s = %(x)s - %(y)s;" % locals() return "%(z)s = %(x)s - %(y)s;" % locals()
def impl(self, x, y): def impl(self, x, y):
return -10 # erroneous (most of the time) return -10 # erroneous (most of the time)
sub = Sub() sub = Sub()
class Mul(Binary): class Mul(Binary):
def c_code(self, node, name, (x, y), (z, ), sub): def c_code(self, node, name, (x, y), (z, ), sub):
return "%(z)s = %(x)s * %(y)s;" % locals() return "%(z)s = %(x)s * %(y)s;" % locals()
def impl(self, x, y): def impl(self, x, y):
return x * y return x * y
mul = Mul() mul = Mul()
class Div(Binary): class Div(Binary):
def c_code(self, node, name, (x, y), (z, ), sub): def c_code(self, node, name, (x, y), (z, ), sub):
return "%(z)s = %(x)s / %(y)s;" % locals() return "%(z)s = %(x)s / %(y)s;" % locals()
...@@ -185,7 +185,7 @@ def test_clinker_dups_inner(): ...@@ -185,7 +185,7 @@ def test_clinker_dups_inner():
lnk = CLinker().accept(Env([x, y, z], [e])) lnk = CLinker().accept(Env([x, y, z], [e]))
fn = lnk.make_function() fn = lnk.make_function()
assert fn(1.0, 2.0, 3.0) == 8.0 assert fn(1.0, 2.0, 3.0) == 8.0
###################### ######################
...@@ -254,7 +254,7 @@ def test_duallinker_mismatch(): ...@@ -254,7 +254,7 @@ def test_duallinker_mismatch():
################################ ################################
# Test that failure code works # # Test that failure code works #
################################ ################################
class AddFail(Binary): class AddFail(Binary):
def c_code(self, node, name, (x, y), (z, ), sub): def c_code(self, node, name, (x, y), (z, ), sub):
fail=sub['fail'] fail=sub['fail']
......
...@@ -32,7 +32,7 @@ class MyOp(Op): ...@@ -32,7 +32,7 @@ class MyOp(Op):
self.name = name self.name = name
if impl: if impl:
self.impl = impl self.impl = impl
def make_node(self, *inputs): def make_node(self, *inputs):
assert len(inputs) == self.nin assert len(inputs) == self.nin
inputs = map(as_variable, inputs) inputs = map(as_variable, inputs)
...@@ -85,7 +85,7 @@ class TestPerformLinker: ...@@ -85,7 +85,7 @@ class TestPerformLinker:
i[1].data = 2 i[1].data = 2
fn() fn()
assert o[0].data == 1.5 assert o[0].data == 1.5
def test_function(self): def test_function(self):
x, y, z = inputs() x, y, z = inputs()
e = mul(add(x, y), div(x, y)) e = mul(add(x, y), div(x, y))
...@@ -130,7 +130,7 @@ class TestWrapLinker: ...@@ -130,7 +130,7 @@ class TestWrapLinker:
nodes = [] nodes = []
def wrap(i, node, th): def wrap(i, node, th):
nodes.append(node.op) nodes.append(node.op)
x, y, z = inputs() x, y, z = inputs()
e = mul(add(x, y), div(x, y)) e = mul(add(x, y), div(x, y))
fn, i, o = wrap_linker(Env([x, y, z], [e]), [PerformLinker(allow_gc=False)], wrap).make_thunk() fn, i, o = wrap_linker(Env([x, y, z], [e]), [PerformLinker(allow_gc=False)], wrap).make_thunk()
...@@ -154,8 +154,8 @@ class TestWrapLinker: ...@@ -154,8 +154,8 @@ class TestWrapLinker:
fn() fn()
assert nodes == [div, add, mul] assert nodes == [div, add, mul]
assert o[0].data == 1.5 assert o[0].data == 1.5
...@@ -15,7 +15,7 @@ def _grad_sources_inputs(*args): ...@@ -15,7 +15,7 @@ def _grad_sources_inputs(*args):
return grad_sources_inputs(warn_type=False, *args) return grad_sources_inputs(warn_type=False, *args)
class test_grad_sources_inputs(unittest.TestCase): class test_grad_sources_inputs(unittest.TestCase):
def test_retNone1(self): def test_retNone1(self):
"""Test that it is not ok to return None from op.grad()""" """Test that it is not ok to return None from op.grad()"""
class retNone(gof.op.Op): class retNone(gof.op.Op):
def make_node(self): def make_node(self):
...@@ -31,7 +31,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -31,7 +31,7 @@ class test_grad_sources_inputs(unittest.TestCase):
self.failUnless(e[0] is gradient._msg_retType) self.failUnless(e[0] is gradient._msg_retType)
return return
self.fail() self.fail()
def test_retNone1_b(self): def test_retNone1_b(self):
"""Test that it is ok to return [None] from op.grad()""" """Test that it is ok to return [None] from op.grad()"""
class retNone(gof.op.Op): class retNone(gof.op.Op):
def make_node(self, *inputs): def make_node(self, *inputs):
...@@ -44,7 +44,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -44,7 +44,7 @@ class test_grad_sources_inputs(unittest.TestCase):
g = _grad_sources_inputs([(a.out, 1)], None) g = _grad_sources_inputs([(a.out, 1)], None)
self.failUnless(not i in g) self.failUnless(not i in g)
def test_wrong_rval_len1(self): def test_wrong_rval_len1(self):
"""Test that it is not ok to return the wrong number of gradients""" """Test that it is not ok to return the wrong number of gradients"""
class retNone(gof.op.Op): class retNone(gof.op.Op):
def make_node(self, *inputs): def make_node(self, *inputs):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论