提交 5dbdadf4 authored 作者: Reyhane Askari's avatar Reyhane Askari

added assertFailure_fast to some tests and minor change in assertFailure_fast

上级 94269225
...@@ -245,6 +245,7 @@ class TestMagma(unittest.TestCase): ...@@ -245,6 +245,7 @@ class TestMagma(unittest.TestCase):
A_val_inv = fn(A_val) A_val_inv = fn(A_val)
utt.assert_allclose(np.eye(N), np.dot(A_val_inv, A_val), atol=1e-2) utt.assert_allclose(np.eye(N), np.dot(A_val_inv, A_val), atol=1e-2)
@utt.assertFailure_fast
def test_gpu_matrix_inverse_inplace(self): def test_gpu_matrix_inverse_inplace(self):
N = 1000 N = 1000
test_rng = np.random.RandomState(seed=1) test_rng = np.random.RandomState(seed=1)
...@@ -255,6 +256,7 @@ class TestMagma(unittest.TestCase): ...@@ -255,6 +256,7 @@ class TestMagma(unittest.TestCase):
fn() fn()
utt.assert_allclose(np.eye(N), np.dot(A_val_gpu.get_value(), A_val_copy), atol=5e-3) utt.assert_allclose(np.eye(N), np.dot(A_val_gpu.get_value(), A_val_copy), atol=5e-3)
@utt.assertFailure_fast
def test_gpu_matrix_inverse_inplace_opt(self): def test_gpu_matrix_inverse_inplace_opt(self):
A = theano.tensor.fmatrix("A") A = theano.tensor.fmatrix("A")
fn = theano.function([A], matrix_inverse(A), mode=mode_with_gpu) fn = theano.function([A], matrix_inverse(A), mode=mode_with_gpu)
...@@ -357,6 +359,7 @@ class TestMagma(unittest.TestCase): ...@@ -357,6 +359,7 @@ class TestMagma(unittest.TestCase):
assert any([isinstance(node.op, GpuMagmaCholesky) assert any([isinstance(node.op, GpuMagmaCholesky)
for node in fn.maker.fgraph.toposort()]) for node in fn.maker.fgraph.toposort()])
@utt.assertFailure_fast
def test_gpu_cholesky_inplace(self): def test_gpu_cholesky_inplace(self):
A = self.rand_symmetric(1000) A = self.rand_symmetric(1000)
A_gpu = gpuarray_shared_constructor(A) A_gpu = gpuarray_shared_constructor(A)
...@@ -367,6 +370,7 @@ class TestMagma(unittest.TestCase): ...@@ -367,6 +370,7 @@ class TestMagma(unittest.TestCase):
L = A_gpu.get_value() L = A_gpu.get_value()
utt.assert_allclose(np.dot(L, L.T), A_copy, atol=1e-3) utt.assert_allclose(np.dot(L, L.T), A_copy, atol=1e-3)
@utt.assertFailure_fast
def test_gpu_cholesky_inplace_opt(self): def test_gpu_cholesky_inplace_opt(self):
A = theano.tensor.fmatrix("A") A = theano.tensor.fmatrix("A")
fn = theano.function([A], GpuMagmaCholesky()(A), mode=mode_with_gpu) fn = theano.function([A], GpuMagmaCholesky()(A), mode=mode_with_gpu)
......
...@@ -5,6 +5,7 @@ import logging ...@@ -5,6 +5,7 @@ import logging
import sys import sys
import unittest import unittest
from parameterized import parameterized from parameterized import parameterized
from nose.tools import assert_raises
from six import integer_types from six import integer_types
from six.moves import StringIO from six.moves import StringIO
...@@ -452,11 +453,8 @@ def assertFailure_fast(f): ...@@ -452,11 +453,8 @@ def assertFailure_fast(f):
THEANO_FLAGS =cycle_detection='fast'. THEANO_FLAGS =cycle_detection='fast'.
""" """
if theano.config.cycle_detection == 'fast': if theano.config.cycle_detection == 'fast':
class TestAssertion(unittest.TestCase): def new_test(*args, **kwargs):
def runTest(self, *args, **kwargs): assert_raises(f, *args, **kwargs)
with self.assertRaises(Exception): return new_test
f(*args, **kwargs)
test_assertion = TestAssertion()
return test_assertion
else: else:
return f return f
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论