From f11c8cdd8fde5dc42b6c4ccbfaeed3074b39b386 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 30 Sep 2017 16:51:07 +0200 Subject: [PATCH] TST: linalg: add basic smoketest for cholesky --- numpy/linalg/tests/test_linalg.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index c612eb6bb62f..3ec0b1299fcb 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -1473,6 +1473,30 @@ def test_0_size(self): class TestCholesky(object): # TODO: are there no other tests for cholesky? + def test_basic_property(self): + # Check A = L L^H + shapes = [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] + dtypes = (np.float32, np.float64, np.complex64, np.complex128) + + for shape, dtype in itertools.product(shapes, dtypes): + np.random.seed(1) + a = np.random.randn(*shape) + if np.issubdtype(dtype, np.complexfloating): + a = a + 1j*np.random.randn(*shape) + + t = list(range(len(shape))) + t[-2:] = -1, -2 + + a = np.matmul(a.transpose(t).conj(), a) + a = np.asarray(a, dtype=dtype) + + c = np.linalg.cholesky(a) + + b = np.matmul(c, c.transpose(t).conj()) + assert_allclose(b, a, + err_msg="{} {}\n{}\n{}".format(shape, dtype, a, c), + atol=500 * a.shape[0] * np.finfo(dtype).eps) + def test_0_size(self): class ArraySubclass(np.ndarray): pass