提交 0f369fc5 authored 作者: James Bergstra's avatar James Bergstra

added unittest to trigger canonizer bug: tensor/tests/test_opt.py:test_add_canonizer_problem0

上级 2445d46f
......@@ -16,6 +16,8 @@ import itertools
import sys
from .. import compile #to register the optimizer built by this file
from ..compile.debugmode import _debugprint
# Utilities
......@@ -669,11 +671,13 @@ class Canonizer(gof.LocalOptimizer):
def transform(self, node):
op = node.op
inputs = node.inputs
out = node.outputs[0]
if op not in [self.main, self.inverse, self.reciprocal]:
return False
inputs = node.inputs
out = node.outputs[0]
assert len(node.outputs) == 1
# I'm not sure if this is actually needed but the following
# block of code puts into "reorg" whether or not we are going
# to change the structure of the graph. For example if we have
......@@ -714,6 +718,12 @@ class Canonizer(gof.LocalOptimizer):
if new.type.broadcastable != out.type.broadcastable:
new = T.fill(out, new)
if 0:
print 'BEFORE'
_debugprint(out, ' ', depth=4)
print 'AFTER'
_debugprint(new, ' ', depth=4)
# if our if's above worked, this should be true. OTW investigate.
if new.type != out.type:
print >> sys.stderr, 'CANONIZE FAILED: new, out = ', new, ',', out, 'types', new.type, ',', out.type
......
......@@ -62,6 +62,15 @@ class test_dimshuffle_lift(unittest.TestCase):
self.failUnless(str(g) == "[add(add(InplaceDimShuffle{x,x,0}(x), InplaceDimShuffle{x,0,1}(y)), z)]", str(g))
def test_add_canonizer_problem0():
#observed in a real graph
n_segments = 10
label = lscalar('label')
segment_labels = label + numpy.asarray([0] * n_segments, dtype='int64')
r = segment_labels * 5
f = function([label], r)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论