Skip to content

Commit 7b26346

Browse files
committed
test/sparse: add test for Simplicial{LLT,LDLT}
1 parent 80c1c7f commit 7b26346

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

unittest/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ endif()
7979
add_lib_unit_test(bind_virtual_factory)
8080

8181
add_python_unit_test("py-matrix" "unittest/python/test_matrix.py" "unittest")
82-
if(BUILD_TESTING_SCIPY)
83-
add_python_unit_test("py-sparse-matrix"
84-
"unittest/python/test_sparse_matrix.py" "unittest")
85-
endif()
8682

8783
add_python_unit_test("py-tensor" "unittest/python/test_tensor.py" "unittest")
8884
add_python_unit_test("py-geometry" "unittest/python/test_geometry.py"
@@ -146,3 +142,19 @@ add_python_unit_test("py-std-unique-ptr"
146142

147143
add_python_unit_test("py-bind-virtual" "unittest/python/test_bind_virtual.py"
148144
"unittest")
145+
146+
if(BUILD_TESTING_SCIPY)
147+
add_python_unit_test("py-sparse-matrix"
148+
"unittest/python/test_sparse_matrix.py" "unittest")
149+
150+
add_python_unit_test(
151+
"py-SimplicialLLT"
152+
"unittest/python/decompositions/sparse/test_SimplicialLLT.py" "python")
153+
add_python_unit_test(
154+
"py-SimplicialLDLT"
155+
"unittest/python/decompositions/sparse/test_SimplicialLDLT.py" "python")
156+
157+
if(BUILD_WITH_CHOLMOD_SUPPORT)
158+
159+
endif(BUILD_WITH_CHOLMOD_SUPPORT)
160+
endif()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import eigenpy
2+
3+
import numpy as np
4+
from scipy.sparse import csc_matrix
5+
6+
dim = 100
7+
A = np.random.rand(dim, dim)
8+
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
9+
10+
A = csc_matrix(A)
11+
12+
ldlt = eigenpy.SimplicialLDLT(A)
13+
14+
assert ldlt.info() == eigenpy.ComputationInfo.Success
15+
16+
L = ldlt.matrixL()
17+
U = ldlt.matrixU()
18+
D = csc_matrix(np.diag(ldlt.vectorD()))
19+
20+
LDU = L @ D @ U
21+
assert eigenpy.is_approx(LDU.toarray(), A.toarray())
22+
23+
X = np.random.rand(dim, 20)
24+
B = A.dot(X)
25+
X_est = ldlt.solve(B)
26+
assert eigenpy.is_approx(X, X_est)
27+
assert eigenpy.is_approx(A.dot(X_est), B)
28+
29+
ldlt.analyzePattern(A)
30+
ldlt.factorize(A)
31+
permutation = ldlt.permutationP()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import eigenpy
2+
3+
import numpy as np
4+
from scipy.sparse import csc_matrix
5+
6+
dim = 100
7+
A = np.random.rand(dim, dim)
8+
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
9+
10+
A = csc_matrix(A)
11+
12+
llt = eigenpy.SimplicialLLT(A)
13+
14+
assert llt.info() == eigenpy.ComputationInfo.Success
15+
16+
L = llt.matrixL()
17+
U = llt.matrixU()
18+
19+
LU = L @ U
20+
assert eigenpy.is_approx(LU.toarray(), A.toarray())
21+
22+
X = np.random.rand(dim, 20)
23+
B = A.dot(X)
24+
X_est = llt.solve(B)
25+
assert eigenpy.is_approx(X, X_est)
26+
assert eigenpy.is_approx(A.dot(X_est), B)
27+
28+
llt.analyzePattern(A)
29+
llt.factorize(A)
30+
permutation = llt.permutationP()

0 commit comments

Comments
 (0)