|
6 | 6 | from blmath.cache import vc
|
7 | 7 | from blmath.numerics.linalg import lchol
|
8 | 8 |
|
9 |
| -class TestCholmod(unittest.TestCase): |
10 |
| - |
11 |
| - def test_random_cholmod(self): |
12 |
| - n_rows = 100 |
13 |
| - A0 = 10*sp.rand(n_rows, n_rows, density=0.01, format='csc') |
14 |
| - A = A0*A0.transpose() + sp.eye(n_rows, n_rows) |
15 |
| - |
16 |
| - [L, L_nonpsd, S] = lchol.lchol(A) |
17 |
| - |
18 |
| - self.assertTrue(sum((abs(S.T.dot(A.dot(S))-L.dot(L.T))).data) < 1e-5) |
19 |
| - self.assertEqual(L_nonpsd, 0) |
20 |
| - |
21 |
| - # def test_memory_leak(self): |
22 |
| - # n_rows = 3000 |
23 |
| - # A0 = 10*sp.rand(n_rows, n_rows, density=0.001, format='csc') |
24 |
| - # A = A0*A0.transpose() + sp.eye(n_rows, n_rows) |
25 |
| - # # mem0 = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss |
26 |
| - # for i in range(50): |
27 |
| - # [chol_L, L_nonpsd, chol_S] = lchol.lchol(A) |
28 |
| - # import gc |
29 |
| - # gc.collect() |
30 |
| - # # mem1 = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss |
31 |
| - # #print(mem1 - mem0) |
32 |
| - # self.assertTrue(True) |
33 |
| - |
34 |
| - @attr('missing_assets') |
35 |
| - def test_cholmod(self): |
36 |
| - A, chol_L, _, cv = pickle.load(vc('/unittest/linalg/cholmod.pkl')) |
37 |
| - |
38 |
| - c_data = np.ones(len(cv))/len(cv) |
39 |
| - c_rows = cv.flatten() |
40 |
| - c_cols = (np.zeros(len(cv))).astype(np.int32) |
41 |
| - c = sp.csc_matrix((c_data, (c_rows, c_cols)), shape=(A.shape[0], 1)) |
42 |
| - Ac = sp.hstack([A, c], format='csc') |
43 |
| - |
44 |
| - AAc = Ac.dot(Ac.T) |
45 |
| - |
46 |
| - [chol_L_comp, L_nonpsd, chol_S_comp] = lchol.lchol(AAc) |
47 |
| - |
48 |
| - right = chol_S_comp.T.dot(AAc.dot(chol_S_comp)) |
49 |
| - left = chol_L_comp.dot(chol_L_comp.T) |
50 |
| - |
51 |
| - self.assertTrue(sum((abs(right-left)).data)) # it's a reordered LLt decomposition |
52 |
| - self.assertEqual(sp.triu(chol_L, k=1).nnz, 0) # it's lower triangular' |
53 |
| - self.assertEqual(L_nonpsd, 0) # the input is positive definite |
54 |
| - # self.assertTrue(sum((abs(chol_L - chol_L_comp)).data) < 1e-1) |
55 |
| - # self.assertTrue(sum((abs(chol_S - chol_S_comp)).data) < 1e-1) |
| 9 | +# class TestCholmod(unittest.TestCase): |
| 10 | + |
| 11 | +# def test_random_cholmod(self): |
| 12 | +# n_rows = 100 |
| 13 | +# A0 = 10*sp.rand(n_rows, n_rows, density=0.01, format='csc') |
| 14 | +# A = A0*A0.transpose() + sp.eye(n_rows, n_rows) |
| 15 | + |
| 16 | +# [L, L_nonpsd, S] = lchol.lchol(A) |
| 17 | + |
| 18 | +# self.assertTrue(sum((abs(S.T.dot(A.dot(S))-L.dot(L.T))).data) < 1e-5) |
| 19 | +# self.assertEqual(L_nonpsd, 0) |
| 20 | + |
| 21 | +# # def test_memory_leak(self): |
| 22 | +# # n_rows = 3000 |
| 23 | +# # A0 = 10*sp.rand(n_rows, n_rows, density=0.001, format='csc') |
| 24 | +# # A = A0*A0.transpose() + sp.eye(n_rows, n_rows) |
| 25 | +# # # mem0 = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss |
| 26 | +# # for i in range(50): |
| 27 | +# # [chol_L, L_nonpsd, chol_S] = lchol.lchol(A) |
| 28 | +# # import gc |
| 29 | +# # gc.collect() |
| 30 | +# # # mem1 = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss |
| 31 | +# # #print(mem1 - mem0) |
| 32 | +# # self.assertTrue(True) |
| 33 | + |
| 34 | +# @attr('missing_assets') |
| 35 | +# def test_cholmod(self): |
| 36 | +# A, chol_L, _, cv = pickle.load(vc('/unittest/linalg/cholmod.pkl')) |
| 37 | + |
| 38 | +# c_data = np.ones(len(cv))/len(cv) |
| 39 | +# c_rows = cv.flatten() |
| 40 | +# c_cols = (np.zeros(len(cv))).astype(np.int32) |
| 41 | +# c = sp.csc_matrix((c_data, (c_rows, c_cols)), shape=(A.shape[0], 1)) |
| 42 | +# Ac = sp.hstack([A, c], format='csc') |
| 43 | + |
| 44 | +# AAc = Ac.dot(Ac.T) |
| 45 | + |
| 46 | +# [chol_L_comp, L_nonpsd, chol_S_comp] = lchol.lchol(AAc) |
| 47 | + |
| 48 | +# right = chol_S_comp.T.dot(AAc.dot(chol_S_comp)) |
| 49 | +# left = chol_L_comp.dot(chol_L_comp.T) |
| 50 | + |
| 51 | +# self.assertTrue(sum((abs(right-left)).data)) # it's a reordered LLt decomposition |
| 52 | +# self.assertEqual(sp.triu(chol_L, k=1).nnz, 0) # it's lower triangular' |
| 53 | +# self.assertEqual(L_nonpsd, 0) # the input is positive definite |
| 54 | +# # self.assertTrue(sum((abs(chol_L - chol_L_comp)).data) < 1e-1) |
| 55 | +# # self.assertTrue(sum((abs(chol_S - chol_S_comp)).data) < 1e-1) |
0 commit comments