提交 db922d3e authored 作者: Frederic Bastien's avatar Frederic Bastien

white space fix.

上级 00b9905c
...@@ -1197,7 +1197,7 @@ class Prod(CAReduce): ...@@ -1197,7 +1197,7 @@ class Prod(CAReduce):
With zeros, things get more complicated. For a given group, we have 3 With zeros, things get more complicated. For a given group, we have 3
cases: cases:
* No zeros in the group. Use previous trick. * No zeros in the group. Use previous trick.
* If only one zero is present, then the gradient for that element is * If only one zero is present, then the gradient for that element is
non-zero, but is zero for all others. non-zero, but is zero for all others.
* If more than one zero is present, then all the derivatives are zero. * If more than one zero is present, then all the derivatives are zero.
...@@ -1209,7 +1209,7 @@ class Prod(CAReduce): ...@@ -1209,7 +1209,7 @@ class Prod(CAReduce):
case, there's a special Op that computes the product of the elements case, there's a special Op that computes the product of the elements
in the group, minus the zero (see ProdWithoutZero). The trick is then in the group, minus the zero (see ProdWithoutZero). The trick is then
to use the division trick for groups with no zero, to use the to use the division trick for groups with no zero, to use the
ProdWithoutZeros op where there's only one zero, and to output a ProdWithoutZeros op where there's only one zero, and to output a
derivative of zero for any element part of a group with more than derivative of zero for any element part of a group with more than
one zero. one zero.
...@@ -1230,14 +1230,14 @@ class Prod(CAReduce): ...@@ -1230,14 +1230,14 @@ class Prod(CAReduce):
axis = range(prod_in.type.ndim) axis = range(prod_in.type.ndim)
if axis == (): if axis == ():
return gz, return gz,
new_dims = [] new_dims = []
i = 0 i = 0
for j, _ in enumerate(prod_in.type.broadcastable): for j, _ in enumerate(prod_in.type.broadcastable):
if j in axis: if j in axis:
new_dims.append('x') new_dims.append('x')
else: else:
new_dims.append(i) new_dims.append(i)
i += 1 i += 1
# result of the product, broadcastable over groups # result of the product, broadcastable over groups
prod_out = self(prod_in).dimshuffle(new_dims) prod_out = self(prod_in).dimshuffle(new_dims)
...@@ -1254,7 +1254,7 @@ class Prod(CAReduce): ...@@ -1254,7 +1254,7 @@ class Prod(CAReduce):
else: else:
T = theano.tensor T = theano.tensor
where_zeros = T.eq(prod_in, 0.0) where_zeros = T.eq(prod_in, 0.0)
sum_where_zeros = T.sum(where_zeros, axis=self.axis) sum_where_zeros = T.sum(where_zeros, axis=self.axis)
groups_with_single_zero = T.eq(sum_where_zeros, 1).dimshuffle(new_dims) groups_with_single_zero = T.eq(sum_where_zeros, 1).dimshuffle(new_dims)
# tensor with 0 everywhere except for those places where # tensor with 0 everywhere except for those places where
...@@ -1262,7 +1262,7 @@ class Prod(CAReduce): ...@@ -1262,7 +1262,7 @@ class Prod(CAReduce):
where_single_zero = groups_with_single_zero * where_zeros where_single_zero = groups_with_single_zero * where_zeros
# further optimization to avoid computing ProdWithoutZeros # further optimization to avoid computing ProdWithoutZeros
# if the incoming gradient is 0 # if the incoming gradient is 0
where_gz_not_zero = T.neq(gz, 0.0) where_gz_not_zero = T.neq(gz, 0.0)
# only take ProdWithoutZeros for the groups with single zeros # only take ProdWithoutZeros for the groups with single zeros
# with non-null incoming gradient # with non-null incoming gradient
where_to_take_prod_without_zeros = \ where_to_take_prod_without_zeros = \
...@@ -1338,4 +1338,3 @@ class ProdWithoutZeros(CAReduce): ...@@ -1338,4 +1338,3 @@ class ProdWithoutZeros(CAReduce):
return "ProdWithoutZeros" return "ProdWithoutZeros"
else: else:
return "ProdWithoutZeros{%s}" % ", ".join(map(str, self.axis)) return "ProdWithoutZeros{%s}" % ", ".join(map(str, self.axis))
...@@ -104,9 +104,9 @@ class test_Broadcast(unittest.TestCase): ...@@ -104,9 +104,9 @@ class test_Broadcast(unittest.TestCase):
xv = numpy.asarray(numpy.random.rand(*xsh)) xv = numpy.asarray(numpy.random.rand(*xsh))
yv = numpy.asarray(numpy.random.rand(*ysh)) yv = numpy.asarray(numpy.random.rand(*ysh))
zv = xv + yv zv = xv + yv
f(xv, yv) f(xv, yv)
assert xv.shape==zv.shape assert xv.shape==zv.shape
def test_perform(self): def test_perform(self):
...@@ -217,11 +217,11 @@ class test_CAReduce(unittest.TestCase): ...@@ -217,11 +217,11 @@ class test_CAReduce(unittest.TestCase):
f(xv) f(xv)
except ValueError: except ValueError:
pass pass
else: else:
self.fail() self.fail()
else: else:
self.failUnless((numpy.abs(f(xv) - zv) < 1e-10).all()) self.failUnless((numpy.abs(f(xv) - zv) < 1e-10).all())
#test CAReduce.infer_shape #test CAReduce.infer_shape
#the Shape op don't implement c_code! #the Shape op don't implement c_code!
...@@ -248,7 +248,7 @@ class test_CAReduce(unittest.TestCase): ...@@ -248,7 +248,7 @@ class test_CAReduce(unittest.TestCase):
self.with_linker(gof.CLinker(), maximum) self.with_linker(gof.CLinker(), maximum)
self.with_linker(gof.CLinker(), minimum) self.with_linker(gof.CLinker(), minimum)
#need other dtype then real #need other dtype then real
#no c_code for or_, and_ #no c_code for or_, and_
#self.with_linker(gof.CLinker(), or_) #self.with_linker(gof.CLinker(), or_)
#self.with_linker(gof.CLinker(), and_) #self.with_linker(gof.CLinker(), and_)
...@@ -367,4 +367,3 @@ if __name__ == '__main__': ...@@ -367,4 +367,3 @@ if __name__ == '__main__':
#suite.addTest(test_Prod('test_prod_without_zeros')) #suite.addTest(test_Prod('test_prod_without_zeros'))
#suite.addTest(test_Prod('test_other_grad_tests')) #suite.addTest(test_Prod('test_other_grad_tests'))
unittest.TextTestRunner().run(suite) unittest.TextTestRunner().run(suite)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论