提交 34864fab authored 作者: Sander Dieleman's avatar Sander Dieleman

Add fast_compile tag so the optimization to remove the Op always runs. Use…

Add fast_compile tag so the optimization to remove the Op always runs. Use g_out.zeros_like instead of tensor.zeros_like so the op also works for sparse variables.
上级 5764be52
......@@ -729,14 +729,14 @@ def fill_diagonal(a, val):
class ConsiderConstant(ViewOp):
def grad(self, args, g_outs):
return [tensor.zeros_like(g_out) for g_out in g_outs]
return [g_out.zeros_like(g_out) for g_out in g_outs]
consider_constant_ = ConsiderConstant()
# Although the op just returns its input, it should be removed from
# the graph to make sure all possible optimizations can be applied.
register_canonicalize(gof.OpRemove(consider_constant_),
name='remove_consider_constant')
'fast_compile', name='remove_consider_constant')
#I create a function only to have the doc show well.
......
......@@ -482,11 +482,10 @@ class TestConsiderConstant(unittest.TestCase):
[node.op for node in f.maker.fgraph.toposort()]
def test_grad(self):
a = numpy.asarray(self.rng.randn(50, 50),
a = numpy.asarray(self.rng.randn(5, 5),
dtype=config.floatX)
x = T.matrix('x')
y = x * consider_constant(x)
expressions_gradients = [
(x * consider_constant(x), x),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论