test_SimplicialLLT.py
Go to the documentation of this file.
1 import numpy as np
2 import scipy
3 from scipy.sparse import csc_matrix
4 
5 import eigenpy
6 
7 dim = 100
8 rng = np.random.default_rng()
9 
10 A = rng.random((dim, dim))
11 A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
12 
13 A = csc_matrix(A)
14 
15 llt = eigenpy.SimplicialLLT(A)
16 
17 assert llt.info() == eigenpy.ComputationInfo.Success
18 
19 L = llt.matrixL()
20 U = llt.matrixU()
21 
22 LU = L @ U
23 assert eigenpy.is_approx(LU.toarray(), A.toarray())
24 
25 X = rng.random((dim, 20))
26 B = A.dot(X)
27 X_est = llt.solve(B)
28 assert eigenpy.is_approx(X, X_est)
29 assert eigenpy.is_approx(A.dot(X_est), B)
30 
31 llt.analyzePattern(A)
32 llt.factorize(A)
33 permutation = llt.permutationP()
34 
35 X_sparse = scipy.sparse.random(dim, 10)
36 B_sparse = A.dot(X_sparse)
37 B_sparse = B_sparse.tocsc(True)
38 
39 if not B_sparse.has_sorted_indices:
40  B_sparse.sort_indices()
41 
42 X_est = llt.solve(B_sparse)
43 assert eigenpy.is_approx(X_est.toarray(), X_sparse.toarray())
44 assert eigenpy.is_approx(A.dot(X_est.toarray()), B_sparse.toarray())
eigenpy::is_approx
EIGEN_DONT_INLINE bool is_approx(const Eigen::SparseMatrixBase< MatrixType1 > &mat1, const Eigen::SparseMatrixBase< MatrixType2 > &mat2)
Definition: is-approx.hpp:36


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Apr 26 2025 02:17:29