20 #ifndef EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H
21 #define EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H
25 template<
typename Derived>
26 void SimplicialCholeskyBase<Derived>::analyzePattern_preordered(
const CholMatrixType& ap,
bool doLDLT)
28 const StorageIndex size = StorageIndex(ap.rows());
29 m_matrix.resize(size, size);
30 m_parent.resize(size);
31 m_nonZerosPerCol.resize(size);
33 ei_declare_aligned_stack_constructed_variable(StorageIndex, tags, size, 0);
35 for(StorageIndex k = 0; k < size; ++k)
40 m_nonZerosPerCol[k] = 0;
41 for(
typename CholMatrixType::InnerIterator it(ap,k); it; ++it)
43 StorageIndex i = it.index();
47 for(; tags[i] != k; i = m_parent[i])
50 if (m_parent[i] == -1)
52 m_nonZerosPerCol[i]++;
60 StorageIndex* Lp = m_matrix.outerIndexPtr();
62 for(StorageIndex k = 0; k < size; ++k)
63 Lp[k+1] = Lp[k] + m_nonZerosPerCol[k] + (doLDLT ? 0 : 1);
65 m_matrix.resizeNonZeros(Lp[size]);
67 m_isInitialized =
true;
69 m_analysisIsOk =
true;
70 m_factorizationIsOk =
false;
74 template<
typename Derived>
76 void SimplicialCholeskyBase<Derived>::factorize_preordered(
const CholMatrixType& ap)
80 eigen_assert(m_analysisIsOk &&
"You must first call analyzePattern()");
81 eigen_assert(ap.rows()==ap.cols());
82 eigen_assert(m_parent.size()==ap.rows());
83 eigen_assert(m_nonZerosPerCol.size()==ap.rows());
85 const StorageIndex size = StorageIndex(ap.rows());
86 const StorageIndex* Lp = m_matrix.outerIndexPtr();
87 StorageIndex* Li = m_matrix.innerIndexPtr();
88 Scalar* Lx = m_matrix.valuePtr();
90 ei_declare_aligned_stack_constructed_variable(Scalar, y, size, 0);
91 ei_declare_aligned_stack_constructed_variable(StorageIndex, pattern, size, 0);
92 ei_declare_aligned_stack_constructed_variable(StorageIndex, tags, size, 0);
95 m_diag.resize(DoLDLT ? size : 0);
97 for(StorageIndex k = 0; k < size; ++k)
101 StorageIndex top = size;
103 m_nonZerosPerCol[k] = 0;
104 for(
typename CholMatrixType::InnerIterator it(ap,k); it; ++it)
106 StorageIndex i = it.index();
109 y[i] += numext::conj(it.value());
111 for(len = 0; tags[i] != k; i = m_parent[i])
117 pattern[--top] = pattern[--len];
123 RealScalar d = numext::real(y[k]) * m_shiftScale + m_shiftOffset;
125 for(; top < size; ++top)
127 Index i = pattern[top];
134 l_ki = yi / numext::real(m_diag[i]);
136 yi = l_ki = yi / Lx[Lp[i]];
138 Index p2 = Lp[i] + m_nonZerosPerCol[i];
140 for(p = Lp[i] + (DoLDLT ? 0 : 1); p < p2; ++p)
141 y[Li[p]] -= numext::conj(Lx[p]) * yi;
142 d -= numext::real(l_ki * numext::conj(yi));
145 ++m_nonZerosPerCol[i];
150 if(d == RealScalar(0))
158 Index p = Lp[k] + m_nonZerosPerCol[k]++;
160 if(d <= RealScalar(0)) {
169 m_factorizationIsOk =
true;
174 #endif // EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H