20 #ifndef EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H
21 #define EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H
23 #include "./InternalHeaderCheck.h"
27 template<
typename Derived>
28 void SimplicialCholeskyBase<Derived>::analyzePattern_preordered(
const CholMatrixType& ap,
bool doLDLT)
30 const StorageIndex size = StorageIndex(ap.rows());
31 m_matrix.resize(size, size);
32 m_parent.resize(size);
33 m_nonZerosPerCol.resize(size);
35 ei_declare_aligned_stack_constructed_variable(StorageIndex, tags, size, 0);
37 for(StorageIndex k = 0; k < size; ++k)
42 m_nonZerosPerCol[k] = 0;
43 for(
typename CholMatrixType::InnerIterator it(ap,k); it; ++it)
45 StorageIndex i = it.index();
49 for(; tags[i] != k; i = m_parent[i])
52 if (m_parent[i] == -1)
54 m_nonZerosPerCol[i]++;
62 StorageIndex* Lp = m_matrix.outerIndexPtr();
64 for(StorageIndex k = 0; k < size; ++k)
65 Lp[k+1] = Lp[k] + m_nonZerosPerCol[k] + (doLDLT ? 0 : 1);
67 m_matrix.resizeNonZeros(Lp[size]);
69 m_isInitialized =
true;
71 m_analysisIsOk =
true;
72 m_factorizationIsOk =
false;
76 template<
typename Derived>
78 void SimplicialCholeskyBase<Derived>::factorize_preordered(
const CholMatrixType& ap)
82 eigen_assert(m_analysisIsOk &&
"You must first call analyzePattern()");
83 eigen_assert(ap.rows()==ap.cols());
84 eigen_assert(m_parent.size()==ap.rows());
85 eigen_assert(m_nonZerosPerCol.size()==ap.rows());
87 const StorageIndex size = StorageIndex(ap.rows());
88 const StorageIndex* Lp = m_matrix.outerIndexPtr();
89 StorageIndex* Li = m_matrix.innerIndexPtr();
90 Scalar* Lx = m_matrix.valuePtr();
92 ei_declare_aligned_stack_constructed_variable(Scalar, y, size, 0);
93 ei_declare_aligned_stack_constructed_variable(StorageIndex, pattern, size, 0);
94 ei_declare_aligned_stack_constructed_variable(StorageIndex, tags, size, 0);
97 m_diag.resize(DoLDLT ? size : 0);
99 for(StorageIndex k = 0; k < size; ++k)
103 StorageIndex top = size;
105 m_nonZerosPerCol[k] = 0;
106 for(
typename CholMatrixType::InnerIterator it(ap,k); it; ++it)
108 StorageIndex i = it.index();
111 y[i] += numext::conj(it.value());
113 for(len = 0; tags[i] != k; i = m_parent[i])
119 pattern[--top] = pattern[--len];
125 RealScalar d = numext::real(y[k]) * m_shiftScale + m_shiftOffset;
127 for(; top < size; ++top)
129 Index i = pattern[top];
136 l_ki = yi / numext::real(m_diag[i]);
138 yi = l_ki = yi / Lx[Lp[i]];
140 Index p2 = Lp[i] + m_nonZerosPerCol[i];
142 for(p = Lp[i] + (DoLDLT ? 0 : 1); p < p2; ++p)
143 y[Li[p]] -= numext::conj(Lx[p]) * yi;
144 d -= numext::real(l_ki * numext::conj(yi));
147 ++m_nonZerosPerCol[i];
152 if(d == RealScalar(0))
160 Index p = Lp[k] + m_nonZerosPerCol[k]++;
162 if(d <= RealScalar(0)) {
171 m_factorizationIsOk =
true;
@ NumericalIssue
Definition: Constants.h:446
@ Success
Definition: Constants.h:444
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)