提交 9a4bf525 authored 作者: James Bergstra's avatar James Bergstra

merge

...@@ -2585,8 +2585,15 @@ class Reshape(Op): ...@@ -2585,8 +2585,15 @@ 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 = as_tensor_variable(shp) shp = as_tensor_variable(shp, ndim=1)
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, [False]*self.ndim)]) if not shp.dtype.startswith('int'):
raise TypeError("Shape must be integers")
assert shp.ndim == 1
if isinstance(shp, TensorConstant):
bcast = [s==1 for s in shp.data]
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, bcast)])
else:
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, [False]*self.ndim)])
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论