8000 Merge pull request #9796 from pv/cholesky-basictest · numpy/numpy@697609c · GitHub
[go: up one dir, main page]

Skip to content

Commit 697609c

Browse files
authored
Merge pull request #9796 from pv/cholesky-basictest
TST: linalg: add basic smoketest for cholesky
2 parents 767744c + 77c873d commit 697609c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

numpy/linalg/tests/test_linalg.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,30 @@ def test_0_size(self):
15071507
class TestCholesky(object):
15081508
# TODO: are there no other tests for cholesky?
15091509

1510+
def test_basic_property(self):
1511+
# Check A = L L^H
1512+
shapes = [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)]
1513+
dtypes = (np.float32, np.float64, np.complex64, np.complex128)
1514+
1515+
for shape, dtype in itertools.product(shapes, dtypes):
1516+
np.random.seed(1)
1517+
a = np.random.randn(*shape)
1518+
if np.issubdtype(dtype, np.complexfloating):
1519+
a = a + 1j*np.random.randn(*shape)
1520+
1521+
t = list(range(len(shape)))
1522+
t[-2:] = -1, -2
1523+
1524+
a = np.matmul(a.transpose(t).conj(), a)
1525+
a = np.asarray(a, dtype=dtype)
1526+
1527+
c = np.linalg.cholesky(a)
1528+
1529+
b = np.matmul(c, c.transpose(t).conj())
1530+
assert_allclose(b, a,
1531+
err_msg="{} {}\n{}\n{}".format(shape, dtype, a, c),
1532+
atol=500 * a.shape[0] * np.finfo(dtype).eps)
1533+
15101534
def test_0_size(self):
15111535
class ArraySubclass(np.ndarray):
15121536
pass

0 commit comments

Comments
 (0)
0