提交 580fa4b5 authored 作者: Frederic Bastien's avatar Frederic Bastien

[BUG new back-end ifelse] Fix gh-5252. Sometimes the ifelse always evaluate to True.

上级 a24ce432
......@@ -249,6 +249,21 @@ class test_gpu_ifelse(test_ifelse.test_ifelse):
def get_ifelse(self, n):
return theano.ifelse.IfElse(n, gpu=True, as_view=True)
def test_lifter_with_inputs_of_graph(self):
x = tensor.vector()
cond = tensor.iscalar()
f = theano.function([x, cond],
theano.ifelse.ifelse(cond, x.mean(), x.sum()),
mode=mode_with_gpu)
assert f(numpy.float32([1, 2, 3]), 0) == 6
x = tensor.vector()
cond = tensor.scalar()
f = theano.function([x, cond],
theano.ifelse.ifelse(cond, x.mean(), x.sum()),
mode=mode_with_gpu)
assert f(numpy.float32([1, 2, 3]), 0) == 6
def test_print_op():
""" Test that print ops don't block gpu optimization"""
......
......@@ -167,10 +167,10 @@ class IfElse(Op):
"Wrong number of arguments to make_node: "
"expected %d, got %d" % (2 * self.n_outs, len(args))
)
c = theano.tensor.as_tensor_variable(c)
if not self.gpu:
# When gpu is true, we are given only cuda ndarrays, and we want
# to keep them be cuda ndarrays
c = theano.tensor.as_tensor_variable(c)
nw_args = []
for x in args:
if isinstance(x, theano.Variable):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论