提交 6b96f677 authored 作者: Frederic's avatar Frederic

Use the real dtype in case of mixed dtype input and work around dtype change…

Use the real dtype in case of mixed dtype input and work around dtype change depending of numpy version.
上级 afffb65c
...@@ -1038,12 +1038,9 @@ class EighGrad(Op): ...@@ -1038,12 +1038,9 @@ class EighGrad(Op):
assert v.ndim == 2 assert v.ndim == 2
assert gw.ndim == 1 assert gw.ndim == 1
assert gv.ndim == 2 assert gv.ndim == 2
if x.dtype == "float32": out_dtype = theano.scalar.upcast(x.dtype, w.dtype, v.dtype,
# The call to self.tri0 in perform upcast from float32 to gw.dtype, gv.dtype)
# float64. out = theano.tensor.matrix(dtype=out_dtype)
out = theano.tensor.matrix(dtype="float64")
else:
out = x.type()
return Apply(self, [x, w, v, gw, gv], [out]) return Apply(self, [x, w, v, gw, gv], [out])
def perform(self, node, inputs, outputs): def perform(self, node, inputs, outputs):
...@@ -1068,7 +1065,13 @@ class EighGrad(Op): ...@@ -1068,7 +1065,13 @@ class EighGrad(Op):
# opposite triangle contributes to variation of two elements # opposite triangle contributes to variation of two elements
# of Hermitian (symmetric) matrix. The following line # of Hermitian (symmetric) matrix. The following line
# implements the necessary logic. # implements the necessary logic.
outputs[0][0] = self.tri0(g) + self.tri1(g).T out = self.tri0(g) + self.tri1(g).T
# The call to self.tri0 in perform upcast from float32 to
# float64 or from int* to int64 in numpy 1.6.1 but not in
# 1.6.2. We do not want version dependent dtype in Theano.
# We think it should be the same as the output.
outputs[0][0] = numpy.asarray(out, dtype=node.outputs[0].dtype)
def infer_shape(self, node, shapes): def infer_shape(self, node, shapes):
return [shapes[0]] return [shapes[0]]
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论