提交 d1631389 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

Merge pull request #197 from nouiz/fix_test

Fix test
...@@ -1117,13 +1117,13 @@ class test_fusion(unittest.TestCase): ...@@ -1117,13 +1117,13 @@ class test_fusion(unittest.TestCase):
# cases[id]=None #to remove g, that link to out that link to the ndarray! # cases[id]=None #to remove g, that link to out that link to the ndarray!
#g.owner.inputs[0] is out... make owner a weakref? #g.owner.inputs[0] is out... make owner a weakref?
class TestCompositeCodegen(unittest.TestCase):
""" class TimesN(theano.scalar.basic.UnaryScalarOp):
Test The Composite Ops code generation in a case where there is multiple """Used in test TestCompositeCodegen
scalar ops with support code.
Must be outside of the class, otherwise, the c cache code can't
pickle this class and this cause stuff printing during test.
""" """
def setUp(self):
class TimesN(theano.scalar.basic.UnaryScalarOp):
def __init__(self, n, *args, **kwargs): def __init__(self, n, *args, **kwargs):
self.n = n self.n = n
theano.scalar.basic.UnaryScalarOp.__init__(self, *args, **kwargs) theano.scalar.basic.UnaryScalarOp.__init__(self, *args, **kwargs)
...@@ -1140,6 +1140,13 @@ class TestCompositeCodegen(unittest.TestCase): ...@@ -1140,6 +1140,13 @@ class TestCompositeCodegen(unittest.TestCase):
def c_code(self, node, name, (x, ), (z, ), sub): def c_code(self, node, name, (x, ), (z, ), sub):
return "%(z)s = %(name)s_timesn(%(x)s);" % locals() return "%(z)s = %(name)s_timesn(%(x)s);" % locals()
class TestCompositeCodegen(unittest.TestCase):
"""
Test The Composite Ops code generation in a case where there is multiple
scalar ops with support code.
"""
def setUp(self):
upgrade_to_float = theano.scalar.basic.upgrade_to_float upgrade_to_float = theano.scalar.basic.upgrade_to_float
self.scal_times_2 = TimesN(2, upgrade_to_float, name='times_2') self.scal_times_2 = TimesN(2, upgrade_to_float, name='times_2')
...@@ -1158,6 +1165,7 @@ class TestCompositeCodegen(unittest.TestCase): ...@@ -1158,6 +1165,7 @@ class TestCompositeCodegen(unittest.TestCase):
y = self.times_2(self.x) y = self.times_2(self.x)
z = self.times_3(y) z = self.times_3(y)
f = function([self.x], z) f = function([self.x], z)
if config.mode != "FAST_COMPILE":
assert len(f.maker.env.toposort()) == 1 assert len(f.maker.env.toposort()) == 1
fval = f([1, 2, 3]) fval = f([1, 2, 3])
assert numpy.all(fval == [6, 12, 18]) assert numpy.all(fval == [6, 12, 18])
...@@ -1174,6 +1182,7 @@ class TestCompositeCodegen(unittest.TestCase): ...@@ -1174,6 +1182,7 @@ class TestCompositeCodegen(unittest.TestCase):
f = theano.function([self.x], cuda.gpu_from_host(z), f = theano.function([self.x], cuda.gpu_from_host(z),
mode=theano.compile.mode.get_default_mode().including('gpu')) mode=theano.compile.mode.get_default_mode().including('gpu'))
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
if config.mode != "FAST_COMPILE":
assert len(topo) == 2 assert len(topo) == 2
assert topo[1].op == cuda.gpu_from_host assert topo[1].op == cuda.gpu_from_host
# topo1 is doing the composite work on the CPU. Auto-generation of # topo1 is doing the composite work on the CPU. Auto-generation of
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论