提交 4c87b1b3 authored 作者: Thomas George's avatar Thomas George

addressed @notoraptor comments

上级 ace491ba
......@@ -8,9 +8,6 @@ from theano import Op
from theano.gpuarray import basic_ops, GpuArrayType
from pygpu.gpuarray import GpuKernel, GpuArray
from string import Template
import numpy as np
from numpy.linalg.linalg import LinAlgError
......
......@@ -1975,7 +1975,7 @@ def local_gpu_solve(op, context_name, inputs, outputs):
def local_gpu_cholesky(op, context_name, inputs, outputs):
if not cusolver_available:
return
return GpuCholesky()
return GpuCholesky(lower=op.lower, inplace=op.destructive)
# Do not register in fast_run or fast_compile.
# It will be added to fast_run if the GPU is enabled.
......
......@@ -120,14 +120,14 @@ class TestGpuCholesky(unittest.TestCase):
utt.seed_rng()
def get_gpu_cholesky_func(self, lower=True, inplace=False):
# Helper function to compile function from GPU Cholesky op.
# Helper function to compile function from GPU Cholesky op.
A = theano.tensor.matrix("A", dtype="float32")
cholesky_op = GpuCholesky(lower=lower, inplace=inplace)
chol_A = cholesky_op(A)
return theano.function([A], chol_A, accept_inplace=inplace, mode=mode_with_gpu)
def compare_gpu_cholesky_to_np(self, A_val, lower=True, inplace=False):
# Helper function to compare op output to np.cholesky output.
# Helper function to compare op output to np.cholesky output.
chol_A_val = np.linalg.cholesky(A_val)
if not lower:
chol_A_val = chol_A_val.T
......@@ -137,27 +137,27 @@ class TestGpuCholesky(unittest.TestCase):
utt.assert_allclose(chol_A_res, chol_A_val)
def test_invalid_input_fail_non_square(self):
# Invalid Cholesky input test with non-square matrix as input.
# Invalid Cholesky input test with non-square matrix as input.
A_val = np.random.normal(size=(3, 2)).astype("float32")
fn = self.get_gpu_cholesky_func(True, False)
self.assertRaises(ValueError, fn, A_val)
def test_invalid_input_fail_vector(self):
# Invalid Cholesky input test with vector as input.
# Invalid Cholesky input test with vector as input.
def invalid_input_func():
A = theano.tensor.vector("A", dtype="float32")
GpuCholesky(lower=True, inplace=False)(A)
self.assertRaises(AssertionError, invalid_input_func)
def test_invalid_input_fail_tensor3(self):
# Invalid Cholesky input test with 3D tensor as input.
# Invalid Cholesky input test with 3D tensor as input.
def invalid_input_func():
A = theano.tensor.tensor3("A", dtype="float32")
GpuCholesky(lower=True, inplace=False)(A)
self.assertRaises(AssertionError, invalid_input_func)
def test_diag_chol(self):
# Diagonal matrix input Cholesky test.
# Diagonal matrix input Cholesky test.
for lower in [True, False]:
for inplace in [True, False]:
# make sure all diagonal elements are positive so positive-definite
......@@ -165,7 +165,7 @@ class TestGpuCholesky(unittest.TestCase):
self.compare_gpu_cholesky_to_np(A_val, lower=lower, inplace=inplace)
def test_dense_chol_lower(self):
# Dense matrix input lower-triangular Cholesky test.
# Dense matrix input lower-triangular Cholesky test.
for lower in [True, False]:
for inplace in [True, False]:
M_val = np.random.normal(size=(3, 3)).astype("float32")
......@@ -185,10 +185,9 @@ class TestGpuCholesky(unittest.TestCase):
self.assertRaises(LinAlgError, fn, A_val)
def test_invalid_input_fail_negative_definite(self):
# Invalid Cholesky input test with negative-definite input.
# Invalid Cholesky input test with negative-definite input.
M_val = np.random.normal(size=(3, 3)).astype("float32")
# A = -M.dot(M) will be negative definite for all non-singular M
A_val = -M_val.dot(M_val.T)
fn = self.get_gpu_cholesky_func(True, False)
self.assertRaises(LinAlgError, fn, A_val)
......@@ -573,7 +573,7 @@ def test_local_lift_solve():
A = tensor.fmatrix()
b = tensor.fmatrix()
o = slinalg.solve(A, b)
f_cpu = theano.function([A, b], o)
f_cpu = theano.function([A, b], o, mode_without_gpu)
f_gpu = theano.function([A, b], o, mode=mode_with_gpu)
assert not any(isinstance(n.op, slinalg.Solve)
for n in f_gpu.maker.fgraph.apply_nodes)
......@@ -589,7 +589,7 @@ def test_local_lift_cholesky():
raise SkipTest('No cuSolver')
A = tensor.fmatrix()
o = slinalg.cholesky(A)
f_cpu = theano.function([A], o)
f_cpu = theano.function([A], o, mode=mode_without_gpu)
f_gpu = theano.function([A], o, mode=mode_with_gpu)
assert not any(isinstance(n.op, slinalg.Cholesky)
for n in f_gpu.maker.fgraph.apply_nodes)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论