提交 ae6a445d authored 作者: Razvan Pascanu's avatar Razvan Pascanu

Two bugs fixed. First one was in printing, pmsg was spelled as psmg. Second one…

Two bugs fixed. First one was in printing, pmsg was spelled as psmg. Second one is more of a temporary fix. neg(x) was optimized to -1*x, where was dtype int which ended up in a dtype error in dot22scalar. I changed the optimization to create a -1 of same dtype as x but fancier solution possible.
上级 b7dda09a
......@@ -88,7 +88,7 @@ class Print(Op):
if callable(temp):
pmsg = temp()
else:
psmg = temp
pmsg = temp
print self.message, attr,'=', pmsg
#backport
#print self.message, attr,'=', temp() if callable(temp) else temp
......
......@@ -900,8 +900,6 @@ def local_dot22_to_dot22scalar(node):
#we take the first _dot22 found. TODO check others!
dot22_idx = i_dot22.index(True)
d = node.inputs[dot22_idx]
i_scalar = [_as_scalar(x) for x in node.inputs]
if not any(i_scalar) and not any([x.owner and x.owner.op ==T.mul for x in node.inputs]):
#no scalar in input and no multiplication
......@@ -938,15 +936,11 @@ def local_dot22_to_dot22scalar(node):
if scalar_idx<0:
info('Not optimizing dot22 with inputs', node.inputs, [x.type for x in node.inputs], 'as the type of the scalar can\'t be upcasted to the matrix type')
return False
assert scalar_idx<len(node.inputs)
s = node.inputs[scalar_idx]
o = copy.copy(node.inputs)
o.remove(d)
o.remove(s)
if len(o)==0:
return [_dot22scalar(d.owner.inputs[0], d.owner.inputs[1], s)]
else:
......
......@@ -1160,7 +1160,8 @@ register_canonicalize(local_mul_canonizer, name = 'local_mul_canonizer')
@gof.local_optimizer([T.neg])
def local_neg_to_mul(node):
if node.op == T.neg:
return [T.mul(-1, node.inputs[0])]
return [T.mul(numpy.array(-1, dtype = node.inputs[0].dtype),
node.inputs[0])]
register_canonicalize(local_neg_to_mul)
@register_specialize
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论