提交 e4d5718c authored 作者: Frederic Bastien's avatar Frederic Bastien

MakeVector.make_node upcast the input to the dtype received in __init__, but…

MakeVector.make_node upcast the input to the dtype received in __init__, but don't allow to loose precission.
上级 60f4eb55
...@@ -227,8 +227,12 @@ class MakeVector(T.Op): ...@@ -227,8 +227,12 @@ class MakeVector(T.Op):
def make_node(self, *inputs): def make_node(self, *inputs):
inputs = map(T.as_tensor_variable, inputs) inputs = map(T.as_tensor_variable, inputs)
if not all(a.type == inputs[0].type for a in inputs): if not all(a.type == inputs[0].type for a in inputs):
raise TypeError('This MakeVector instance requires inputs of same type %s' % dtype=theano.scalar.upcast(self.dtype,*[i.dtype for i in inputs])
inputs[0].type) #upcast the input to the determined dtype, but don't upcast downcast anything
assert dtype==self.dtype, "Upcast the input of MakeVector to dtype gived in init without precissino loss only."
inputs=[T.cast(i,dtype=dtype) for i in inputs]
assert all(a.type == inputs[0].type for a in inputs)
if inputs: if inputs:
dtype = inputs[0].type.dtype dtype = inputs[0].type.dtype
else: else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论