提交 1ac53176 authored 作者: Frederic's avatar Frederic

make test under theano/gof pass when no c++ compiler.

上级 df5d07f0
import unittest import unittest
from nose.plugins.skip import SkipTest
from theano.gof.link import PerformLinker from theano.gof.link import PerformLinker
from theano.gof.cc import * from theano.gof.cc import *
from theano.gof.type import Type from theano.gof.type import Type
...@@ -179,6 +181,8 @@ def Env(inputs, outputs): ...@@ -179,6 +181,8 @@ def Env(inputs, outputs):
################ ################
def test_clinker_straightforward(): def test_clinker_straightforward():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x, y, z = inputs() x, y, z = inputs()
e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z)) e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z))
lnk = CLinker().accept(Env([x, y, z], [e])) lnk = CLinker().accept(Env([x, y, z], [e]))
...@@ -187,6 +191,8 @@ def test_clinker_straightforward(): ...@@ -187,6 +191,8 @@ def test_clinker_straightforward():
def test_clinker_literal_inlining(): def test_clinker_literal_inlining():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x, y, z = inputs() x, y, z = inputs()
z = Constant(tdouble, 4.12345678) z = Constant(tdouble, 4.12345678)
e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z)) e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z))
...@@ -200,6 +206,8 @@ def test_clinker_literal_inlining(): ...@@ -200,6 +206,8 @@ def test_clinker_literal_inlining():
def test_clinker_single_node(): def test_clinker_single_node():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x, y, z = inputs() x, y, z = inputs()
node = add.make_node(x, y) node = add.make_node(x, y)
lnk = CLinker().accept(Env(node.inputs, node.outputs)) lnk = CLinker().accept(Env(node.inputs, node.outputs))
...@@ -208,6 +216,8 @@ def test_clinker_single_node(): ...@@ -208,6 +216,8 @@ def test_clinker_single_node():
def test_clinker_dups(): def test_clinker_dups():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
# Testing that duplicate inputs are allowed. # Testing that duplicate inputs are allowed.
x, y, z = inputs() x, y, z = inputs()
e = add(x, x) e = add(x, x)
...@@ -218,6 +228,8 @@ def test_clinker_dups(): ...@@ -218,6 +228,8 @@ def test_clinker_dups():
def test_clinker_dups_inner(): def test_clinker_dups_inner():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
# Testing that duplicates are allowed inside the graph # Testing that duplicates are allowed inside the graph
x, y, z = inputs() x, y, z = inputs()
e = add(mul(y, y), add(x, z)) e = add(mul(y, y), add(x, z))
...@@ -235,8 +247,11 @@ def test_opwiseclinker_straightforward(): ...@@ -235,8 +247,11 @@ def test_opwiseclinker_straightforward():
e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z)) e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z))
lnk = OpWiseCLinker().accept(Env([x, y, z], [e])) lnk = OpWiseCLinker().accept(Env([x, y, z], [e]))
fn = lnk.make_function() fn = lnk.make_function()
assert fn(2.0, 2.0, 2.0) == 2.0 if theano.config.cxx:
assert fn(2.0, 2.0, 2.0) == 2.0
else:
# The python version of bad_sub always return -10.
assert fn(2.0, 2.0, 2.0) == -6
def test_opwiseclinker_constant(): def test_opwiseclinker_constant():
x, y, z = inputs() x, y, z = inputs()
...@@ -272,6 +287,8 @@ def test_duallinker_straightforward(): ...@@ -272,6 +287,8 @@ def test_duallinker_straightforward():
def test_duallinker_mismatch(): def test_duallinker_mismatch():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x, y, z = inputs() x, y, z = inputs()
# bad_sub is correct in C but erroneous in Python # bad_sub is correct in C but erroneous in Python
e = bad_sub(mul(x, y), mul(y, z)) e = bad_sub(mul(x, y), mul(y, z))
...@@ -315,7 +332,9 @@ class AddFail(Binary): ...@@ -315,7 +332,9 @@ class AddFail(Binary):
add_fail = AddFail() add_fail = AddFail()
def test_fail_error(): def test_c_fail_error():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
x, y, z = inputs() x, y, z = inputs()
x = Constant(tdouble, 7.2, name='x') x = Constant(tdouble, 7.2, name='x')
e = add_fail(mul(x, y), mul(y, z)) e = add_fail(mul(x, y), mul(y, z))
......
import os, sys, traceback, warnings import os, sys, traceback, warnings
import numpy import numpy
from nose.plugins.skip import SkipTest
import unittest import unittest
import theano import theano
...@@ -334,6 +335,8 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -334,6 +335,8 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
def test_no_perform(self): def test_no_perform(self):
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
class IncOneC(Op): class IncOneC(Op):
"""An Op with only a C (c_code) implementation""" """An Op with only a C (c_code) implementation"""
......
...@@ -184,12 +184,15 @@ class TestMakeThunk(unittest.TestCase): ...@@ -184,12 +184,15 @@ class TestMakeThunk(unittest.TestCase):
thunk = o.owner.op.make_thunk(o.owner, storage_map, compute_map, thunk = o.owner.op.make_thunk(o.owner, storage_map, compute_map,
no_recycling=[]) no_recycling=[])
if theano.config.cxx:
required = thunk() required = thunk()
# Check everything went OK # Check everything went OK
assert not required # We provided all inputs assert not required # We provided all inputs
assert compute_map[o][0] assert compute_map[o][0]
assert storage_map[o][0] == 4 assert storage_map[o][0] == 4
else:
self.assertRaises((NotImplementedError, utils.MethodNotDefined),
thunk)
def test_test_value_python_objects(): def test_test_value_python_objects():
......
...@@ -6,6 +6,8 @@ try: ...@@ -6,6 +6,8 @@ try:
import line_profiler import line_profiler
except ImportError: except ImportError:
pass pass
from nose.plugins.skip import SkipTest
import numpy import numpy
from theano import function from theano import function
...@@ -55,6 +57,8 @@ class TestCallbacks(unittest.TestCase): ...@@ -55,6 +57,8 @@ class TestCallbacks(unittest.TestCase):
def test_speed(): def test_speed():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
def build_graph(x, depth=5): def build_graph(x, depth=5):
z = x z = x
...@@ -124,8 +128,9 @@ def test_speed(): ...@@ -124,8 +128,9 @@ def test_speed():
time_linker('c|py', OpWiseCLinker) time_linker('c|py', OpWiseCLinker)
time_linker('vmLinker', vm.VM_Linker) time_linker('vmLinker', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False)) time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False))
time_linker('vmLinker_CLOOP', lambda : vm.VM_Linker(allow_gc=False, if theano.config.cxx:
use_cloop=True)) time_linker('vmLinker_CLOOP', lambda : vm.VM_Linker(allow_gc=False,
use_cloop=True))
time_numpy() time_numpy()
def test_speed_lazy(): def test_speed_lazy():
...@@ -175,8 +180,9 @@ def test_speed_lazy(): ...@@ -175,8 +180,9 @@ def test_speed_lazy():
time_linker('vmLinker', vm.VM_Linker) time_linker('vmLinker', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False)) time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False))
time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False, if theano.config.cxx:
use_cloop=True)) time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False,
use_cloop=True))
run_memory_usage_tests = False run_memory_usage_tests = False
if run_memory_usage_tests: if run_memory_usage_tests:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论