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

Fix for ticket #434. Appears not to break anything.

上级 ce291230
...@@ -3385,6 +3385,7 @@ class Reshape(Op): ...@@ -3385,6 +3385,7 @@ class Reshape(Op):
return '%s{%s}' %(self.__class__.__name__, self.ndim) return '%s{%s}' %(self.__class__.__name__, self.ndim)
def make_node(self, x, shp): def make_node(self, x, shp):
x = as_tensor_variable(x) x = as_tensor_variable(x)
shp_orig = shp
shp = as_tensor_variable(shp, ndim=1) shp = as_tensor_variable(shp, ndim=1)
if not shp.dtype.startswith('int'): if not shp.dtype.startswith('int'):
raise TypeError("Shape must be integers") raise TypeError("Shape must be integers")
...@@ -3393,7 +3394,16 @@ class Reshape(Op): ...@@ -3393,7 +3394,16 @@ class Reshape(Op):
bcast = [s==1 for s in shp.data] bcast = [s==1 for s in shp.data]
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, bcast)]) return gof.Apply(self, [x, shp], [tensor(x.type.dtype, bcast)])
else: else:
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, [False]*self.ndim)]) bcasts = [False] * self.ndim
for index in xrange(self.ndim):
y = shp_orig[index]
# Try to see if we can infer that y has a constant value of 1.
# If so, that dimension should be broadcastable.
try:
bcasts[index] = (hasattr(y, 'get_constant_value') and y.get_constant_value() == 1)
except TypeError:
pass
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, bcasts)])
def perform(self, node, (x, shp), (out,)): def perform(self, node, (x, shp), (out,)):
if (len(shp) != self.ndim): if (len(shp) != self.ndim):
raise ValueError('shape argument to Reshape.perform has incorrect length %i' raise ValueError('shape argument to Reshape.perform has incorrect length %i'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论