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

Fix MakeVector.make_node when their is 0 inputs. It was working in the past and was used.

上级 3f66dba3
......@@ -217,6 +217,7 @@ class MakeVector(T.Op):
This is a simple version of stack() that introduces far less cruft into the graph.
Should work with 0 inputs.
"""
def __init__(self, dtype='int64'):
self.dtype = dtype
......@@ -226,7 +227,7 @@ class MakeVector(T.Op):
return hash(type(self)) ^ hash(self.dtype)
def make_node(self, *inputs):
inputs = map(T.as_tensor_variable, inputs)
if not all(a.type == inputs[0].type for a in inputs) or inputs[0].dtype != self.dtype:
if not all(a.type == inputs[0].type for a in inputs) or (len(inputs)>0 and inputs[0].dtype != self.dtype):
dtype=theano.scalar.upcast(self.dtype,*[i.dtype for i in inputs])
#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."
......
......@@ -1637,17 +1637,19 @@ class T_local_sum_dimshuffle(unittest.TestCase):
# test_local_sum_prod_dimshuffle (a * b * c)
# test_local_sum_divprod_dimshuffle ((a * b) / (c * d))
def test_make_vector_upcast():
def test_make_vector():
b = T.bscalar()
i = T.iscalar()
d = T.dscalar()
opt.MakeVector(dtype="int8")(b,b)
opt.MakeVector(dtype="int32")(i,b)
opt.MakeVector(dtype="int32")(b,i)
opt.MakeVector(dtype="float64")(b,i)
opt.MakeVector(dtype="float64")(b,d)
opt.MakeVector(dtype="float64")(d,i)
assert opt.MakeVector(dtype="int8")(b,b).dtype=="int8"
assert opt.MakeVector(dtype="int32")(i,b).dtype=="int32"
assert opt.MakeVector(dtype="int32")(b,i).dtype=="int32"
assert opt.MakeVector(dtype="float64")(b,i).dtype=="float64"
assert opt.MakeVector(dtype="float64")(b,d).dtype=="float64"
assert opt.MakeVector(dtype="float64")(d,i).dtype=="float64"
assert opt.MakeVector(dtype="float64")().dtype=="float64"
assert opt.MakeVector(dtype="int64")().dtype=="int64"
#should fail
for (dtype,inputs) in [("int8",(b,i)),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论