test_SimplicialLDLT.py
Go to the documentation of this file.
1 import numpy as np
2 from scipy.sparse import csc_matrix
3 
4 import eigenpy
5 
6 dim = 100
7 rng = np.random.default_rng()
8 
9 A = rng.random((dim, dim))
10 A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
11 
12 A = csc_matrix(A)
13 
14 ldlt = eigenpy.SimplicialLDLT(A)
15 
16 assert ldlt.info() == eigenpy.ComputationInfo.Success
17 
18 L = ldlt.matrixL()
19 U = ldlt.matrixU()
20 D = csc_matrix(np.diag(ldlt.vectorD()))
21 
22 LDU = L @ D @ U
23 assert eigenpy.is_approx(LDU.toarray(), A.toarray())
24 
25 X = rng.random((dim, 20))
26 B = A.dot(X)
27 X_est = ldlt.solve(B)
28 assert eigenpy.is_approx(X, X_est)
29 assert eigenpy.is_approx(A.dot(X_est), B)
30 
31 ldlt.analyzePattern(A)
32 ldlt.factorize(A)
33 permutation = ldlt.permutationP()
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 Fri Jun 14 2024 02:15:58