提交 23527587 authored 作者: Alexander Matyasko's avatar Alexander Matyasko

Small updates to tests

上级 9d413f18
...@@ -210,7 +210,7 @@ class TestMagma(unittest.TestCase): ...@@ -210,7 +210,7 @@ class TestMagma(unittest.TestCase):
def test_gpu_matrix_inverse(self): def test_gpu_matrix_inverse(self):
A = theano.tensor.fmatrix("A") A = theano.tensor.fmatrix("A")
fn = theano.function([A], gpu_matrix_inverse(A), mode=mode_with_gpu.including('magma')) fn = theano.function([A], gpu_matrix_inverse(A), mode=mode_with_gpu)
N = 1000 N = 1000
A_val = rand(N, N) A_val = rand(N, N)
A_val_inv = fn(A_val) A_val_inv = fn(A_val)
...@@ -221,15 +221,13 @@ class TestMagma(unittest.TestCase): ...@@ -221,15 +221,13 @@ class TestMagma(unittest.TestCase):
A_val_gpu = gpuarray_shared_constructor(rand(N, N)) A_val_gpu = gpuarray_shared_constructor(rand(N, N))
A_val_copy = A_val_gpu.get_value() A_val_copy = A_val_gpu.get_value()
fn = theano.function([], gpu_matrix_inverse(A_val_gpu, inplace=True), fn = theano.function([], gpu_matrix_inverse(A_val_gpu, inplace=True),
mode=mode_with_gpu.including('magma'), mode=mode_with_gpu, accept_inplace=True)
accept_inplace=True)
fn() fn()
utt.assert_allclose(np.dot(A_val_gpu.get_value(), A_val_copy), np.eye(N), atol=1e-3) utt.assert_allclose(np.dot(A_val_gpu.get_value(), A_val_copy), np.eye(N), atol=1e-3)
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), fn = theano.function([A], matrix_inverse(A), mode=mode_with_gpu)
mode=mode_with_gpu.including('magma'))
assert any([ assert any([
node.op.inplace node.op.inplace
for node in fn.maker.fgraph.toposort() if for node in fn.maker.fgraph.toposort() if
...@@ -240,7 +238,7 @@ class TestMagma(unittest.TestCase): ...@@ -240,7 +238,7 @@ class TestMagma(unittest.TestCase):
A = theano.tensor.fmatrix("A") A = theano.tensor.fmatrix("A")
f = theano.function( f = theano.function(
[A], gpu_svd(A, full_matrices=full_matrices, compute_uv=compute_uv), [A], gpu_svd(A, full_matrices=full_matrices, compute_uv=compute_uv),
mode=mode_with_gpu.including('magma')) mode=mode_with_gpu)
return f(A_val) return f(A_val)
def assert_column_orthonormal(self, Ot): def assert_column_orthonormal(self, Ot):
...@@ -288,8 +286,7 @@ class TestMagma(unittest.TestCase): ...@@ -288,8 +286,7 @@ class TestMagma(unittest.TestCase):
[A], theano.tensor.nlinalg.svd(A, compute_uv=False), [A], theano.tensor.nlinalg.svd(A, compute_uv=False),
mode=mode_without_gpu) mode=mode_without_gpu)
f_gpu = theano.function( f_gpu = theano.function(
[A], gpu_svd(A, compute_uv=False), [A], gpu_svd(A, compute_uv=False), mode=mode_with_gpu)
mode=mode_with_gpu.including('magma'))
A_val = rand(50, 100) A_val = rand(50, 100)
utt.assert_allclose(f_cpu(A_val), f_gpu(A_val)) utt.assert_allclose(f_cpu(A_val), f_gpu(A_val))
......
...@@ -140,11 +140,10 @@ class test_SVD(utt.InferShapeTester): ...@@ -140,11 +140,10 @@ class test_SVD(utt.InferShapeTester):
self.op = svd self.op = svd
def test_svd(self): def test_svd(self):
rng = np.random.RandomState(utt.fetch_seed())
A = tensor.matrix("A", dtype=self.dtype) A = tensor.matrix("A", dtype=self.dtype)
U, S, VT = svd(A) U, S, VT = svd(A)
fn = function([A], [U, S, VT]) fn = function([A], [U, S, VT])
a = rng.rand(4, 4).astype(self.dtype) a = self.rng.rand(4, 4).astype(self.dtype)
n_u, n_s, n_vt = np.linalg.svd(a) n_u, n_s, n_vt = np.linalg.svd(a)
t_u, t_s, t_vt = fn(a) t_u, t_s, t_vt = fn(a)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论