提交 b155c92f authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix bug recently introduced in ShapeFeature

上级 d1b923fd
...@@ -618,11 +618,10 @@ class ShapeFeature(object): ...@@ -618,11 +618,10 @@ class ShapeFeature(object):
assert other_r in self.shape_of, ('other_r not in shape_of', other_r) assert other_r in self.shape_of, ('other_r not in shape_of', other_r)
other_shape = self.shape_of[other_r] other_shape = self.shape_of[other_r]
# If no info is known on r's shape, use other_shape if r in self.shape_of:
try: r_shape = self.shape_of[r]
r_shape = self.shape_tuple(r) else:
except AttributeError, e: # If no info is known on r's shape, use other_shape
#print e
self.shape_of[r] = other_shape self.shape_of[r] = other_shape
return return
...@@ -634,11 +633,14 @@ class ShapeFeature(object): ...@@ -634,11 +633,14 @@ class ShapeFeature(object):
# Merge other_shape with r_shape, giving the priority to other_shape # Merge other_shape with r_shape, giving the priority to other_shape
merged_shape = [] merged_shape = []
for i, ps in enumerate(other_shape): for i, ps in enumerate(other_shape):
# If other_shape[i] is uninformative (if it is just # If other_shape[i] is uninformative, use r_shape[i].
# Shape_i(i)(other_r)), use r_shape[i] # For now, we consider 2 cases of uninformative other_shape[i]:
if (isinstance(getattr(ps,'op',None), Shape_i) and # - Shape_i(i)(other_r);
ps.i == i and # - Shape_i(i)(r).
ps.inputs[0] == other_r): if (ps.owner and
isinstance(getattr(ps.owner,'op',None), Shape_i) and
ps.owner.op.i == i and
ps.owner.inputs[0] in (r, other_r)):
merged_shape.append(r_shape[i]) merged_shape.append(r_shape[i])
else: else:
merged_shape.append(other_shape[i]) merged_shape.append(other_shape[i])
......
...@@ -1670,7 +1670,7 @@ class test_shapeoptimizer(unittest.TestCase): ...@@ -1670,7 +1670,7 @@ class test_shapeoptimizer(unittest.TestCase):
register_specialize(local_identity_noshape_to_identity_shape) register_specialize(local_identity_noshape_to_identity_shape)
# With the optimization # With the optimization
# The identity_shape op is should not be needed anymore to compute # The identity_shape op should not be needed anymore to compute
# the shape # the shape
g = theano.function([x], ins_x.shape, mode=mode) g = theano.function([x], ins_x.shape, mode=mode)
xval = rng.randn(6,1,2).astype(config.floatX) xval = rng.randn(6,1,2).astype(config.floatX)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论