提交 aa4ac20e authored 作者: Frederic's avatar Frederic

Make tests pass when there is no c++ compiler in theano/compile

上级 08cf79e4
...@@ -197,19 +197,22 @@ wb1 = WeirdBrokenOp('times1') ...@@ -197,19 +197,22 @@ wb1 = WeirdBrokenOp('times1')
def test_badthunkoutput(): def test_badthunkoutput():
# Check if the c and python code is consistent.
a = theano.tensor.dvector() a = theano.tensor.dvector()
b = theano.tensor.dvector() b = theano.tensor.dvector()
f_good = theano.function([a, b], f_good = theano.function([a, b],
off_by_half(a, b), off_by_half(a, b),
mode=debugmode.DebugMode(check_c_code=True)) mode=debugmode.DebugMode(check_c_code=theano.config.cxx))
f_inconsistent = theano.function([a, b], f_inconsistent = theano.function([a, b],
inconsistent(a, b), inconsistent(a, b),
mode=debugmode.DebugMode(check_c_code=True)) mode=debugmode.DebugMode(check_c_code=theano.config.cxx))
#this should evaluate with no error #this should evaluate with no error
f_good([1.0, 2.0, 3.0], [2, 3, 4]) f_good([1.0, 2.0, 3.0], [2, 3, 4])
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
try: try:
f_inconsistent([1.0, 2.0, 3.0], [2, 3, 4]) f_inconsistent([1.0, 2.0, 3.0], [2, 3, 4])
except debugmode.BadThunkOutput, e: except debugmode.BadThunkOutput, e:
...@@ -234,7 +237,7 @@ def test_badoptimization(): ...@@ -234,7 +237,7 @@ def test_badoptimization():
b = theano.tensor.dvector() b = theano.tensor.dvector()
f = theano.function([a, b], a + b, f = theano.function([a, b], a + b,
mode=debugmode.DebugMode(optimizer=opt, check_c_code=True)) mode=debugmode.DebugMode(optimizer=opt))
try: try:
f([1.0, 2.0, 3.0], [2, 3, 4],) f([1.0, 2.0, 3.0], [2, 3, 4],)
...@@ -282,6 +285,8 @@ def test_stochasticoptimization(): ...@@ -282,6 +285,8 @@ def test_stochasticoptimization():
def test_just_c_code(): def test_just_c_code():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x = theano.tensor.dvector() x = theano.tensor.dvector()
f = theano.function([x], wb2(x), f = theano.function([x], wb2(x),
mode=debugmode.DebugMode(check_py_code=False)) mode=debugmode.DebugMode(check_py_code=False))
...@@ -312,6 +317,8 @@ def test_baddestroymap(): ...@@ -312,6 +317,8 @@ def test_baddestroymap():
def test_baddestroymap_c(): def test_baddestroymap_c():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x = theano.tensor.dvector() x = theano.tensor.dvector()
f = theano.function([x], wb2i(x), f = theano.function([x], wb2i(x),
mode=debugmode.DebugMode(check_py_code=False)) mode=debugmode.DebugMode(check_py_code=False))
...@@ -378,6 +385,8 @@ class Test_ViewMap(unittest.TestCase): ...@@ -378,6 +385,8 @@ class Test_ViewMap(unittest.TestCase):
assert False # failed to raise error assert False # failed to raise error
def test_badviewmap_c(self): def test_badviewmap_c(self):
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x = theano.tensor.dvector() x = theano.tensor.dvector()
f = theano.function([x], wb1i(x), f = theano.function([x], wb1i(x),
mode=debugmode.DebugMode(check_py_code=False)) mode=debugmode.DebugMode(check_py_code=False))
...@@ -721,7 +730,12 @@ class Test_preallocated_output(unittest.TestCase): ...@@ -721,7 +730,12 @@ class Test_preallocated_output(unittest.TestCase):
check_preallocated_output=['f_contiguous']) check_preallocated_output=['f_contiguous'])
f = theano.function([a, b], out, mode=mode) f = theano.function([a, b], out, mode=mode)
if theano.config.cxx:
self.assertRaises(debugmode.BadThunkOutput, f, a_val, b_val) self.assertRaises(debugmode.BadThunkOutput, f, a_val, b_val)
else:
# The python code of this op is good.
f(a_val, b_val)
def test_output_broadcast_tensor(self): def test_output_broadcast_tensor(self):
v = theano.tensor.fvector('v') v = theano.tensor.fvector('v')
......
...@@ -22,7 +22,11 @@ class T_bunch_of_modes(unittest.TestCase): ...@@ -22,7 +22,11 @@ class T_bunch_of_modes(unittest.TestCase):
predef_modes.append(ProfileMode()) predef_modes.append(ProfileMode())
# Linkers to use with regular Mode # Linkers to use with regular Mode
linkers = ['c|py', 'c|py_nogc', 'vm', 'vm_nogc', 'cvm', 'cvm_nogc'] if theano.config.cxx:
linkers = ['py', 'c|py', 'c|py_nogc', 'vm', 'vm_nogc',
'cvm', 'cvm_nogc']
else:
linkers = ['py', 'c|py', 'c|py_nogc', 'vm', 'vm_nogc']
modes = predef_modes + [Mode(linker, 'fast_run') for linker in linkers] modes = predef_modes + [Mode(linker, 'fast_run') for linker in linkers]
for mode in modes: for mode in modes:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论