Skip to content
Snippets Groups Projects
Commit 7b26346e authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test/sparse: add test for Simplicial{LLT,LDLT}

parent 80c1c7f1
No related branches found
No related tags found
No related merge requests found
......@@ -79,10 +79,6 @@ endif()
add_lib_unit_test(bind_virtual_factory)
add_python_unit_test("py-matrix" "unittest/python/test_matrix.py" "unittest")
if(BUILD_TESTING_SCIPY)
add_python_unit_test("py-sparse-matrix"
"unittest/python/test_sparse_matrix.py" "unittest")
endif()
add_python_unit_test("py-tensor" "unittest/python/test_tensor.py" "unittest")
add_python_unit_test("py-geometry" "unittest/python/test_geometry.py"
......@@ -146,3 +142,19 @@ add_python_unit_test("py-std-unique-ptr"
add_python_unit_test("py-bind-virtual" "unittest/python/test_bind_virtual.py"
"unittest")
if(BUILD_TESTING_SCIPY)
add_python_unit_test("py-sparse-matrix"
"unittest/python/test_sparse_matrix.py" "unittest")
add_python_unit_test(
"py-SimplicialLLT"
"unittest/python/decompositions/sparse/test_SimplicialLLT.py" "python")
add_python_unit_test(
"py-SimplicialLDLT"
"unittest/python/decompositions/sparse/test_SimplicialLDLT.py" "python")
if(BUILD_WITH_CHOLMOD_SUPPORT)
endif(BUILD_WITH_CHOLMOD_SUPPORT)
endif()
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
A = csc_matrix(A)
ldlt = eigenpy.SimplicialLDLT(A)
assert ldlt.info() == eigenpy.ComputationInfo.Success
L = ldlt.matrixL()
U = ldlt.matrixU()
D = csc_matrix(np.diag(ldlt.vectorD()))
LDU = L @ D @ U
assert eigenpy.is_approx(LDU.toarray(), A.toarray())
X = np.random.rand(dim, 20)
B = A.dot(X)
X_est = ldlt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
ldlt.analyzePattern(A)
ldlt.factorize(A)
permutation = ldlt.permutationP()
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
A = csc_matrix(A)
llt = eigenpy.SimplicialLLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
L = llt.matrixL()
U = llt.matrixU()
LU = L @ U
assert eigenpy.is_approx(LU.toarray(), A.toarray())
X = np.random.rand(dim, 20)
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
llt.analyzePattern(A)
llt.factorize(A)
permutation = llt.permutationP()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment