提交 568ca1e0 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

used cast to avoid unimplemented sparse-dense multiply

上级 6c433b9d
......@@ -989,7 +989,19 @@ class DenseFromSparse(gof.op.Op):
def grad(self, (x, ), (gz, )):
if self.sparse_grad:
return [sp_ones_like(x) * gz]
left = sp_ones_like(x)
right = gz
# Do upcasting if necessary to avoid an unimplemented case
# of mul
if right.dtype == 'float64' and left.dtype == 'float32':
left = left.astype('float64')
if right.dtype == 'float32' and left.dtype == 'float64':
right = right.astype('float64')
return [left * right]
else:
return [SparseFromDense(x.type.format)(gz)]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论