10 #ifndef EIGEN_INCOMPLETE_LUT_H 11 #define EIGEN_INCOMPLETE_LUT_H 27 template <
typename VectorV,
typename VectorI,
typename Index>
28 Index QuickSplit(VectorV &row, VectorI &ind, Index ncut)
30 typedef typename VectorV::RealScalar RealScalar;
40 if (ncut < first || ncut > last )
return 0;
44 RealScalar abskey = abs(row(mid));
45 for (Index j = first + 1; j <= last; j++) {
46 if ( abs(row(j)) > abskey) {
48 swap(row(mid), row(j));
49 swap(ind(mid), ind(j));
53 swap(row(mid), row(first));
54 swap(ind(mid), ind(first));
56 if (mid > ncut) last = mid - 1;
57 else if (mid < ncut ) first = mid + 1;
58 }
while (mid != ncut );
95 template <
typename _Scalar>
103 typedef typename FactorType::Index Index;
110 m_analysisIsOk(
false), m_factorizationIsOk(
false), m_isInitialized(
false)
113 template<
typename MatrixType>
115 : m_droptol(droptol),m_fillfactor(fillfactor),
116 m_analysisIsOk(
false),m_factorizationIsOk(
false),m_isInitialized(
false)
118 eigen_assert(fillfactor != 0);
122 Index rows()
const {
return m_lu.rows(); }
124 Index cols()
const {
return m_lu.cols(); }
133 eigen_assert(m_isInitialized &&
"IncompleteLUT is not initialized.");
137 template<
typename MatrixType>
138 void analyzePattern(
const MatrixType& amat);
140 template<
typename MatrixType>
141 void factorize(
const MatrixType& amat);
148 template<
typename MatrixType>
151 analyzePattern(amat);
156 void setDroptol(
const RealScalar& droptol);
157 void setFillfactor(
int fillfactor);
159 template<
typename Rhs,
typename Dest>
160 void _solve(
const Rhs& b, Dest& x)
const 163 x = m_lu.template triangularView<UnitLower>().solve(x);
164 x = m_lu.template triangularView<Upper>().solve(x);
171 eigen_assert(m_isInitialized &&
"IncompleteLUT is not initialized.");
172 eigen_assert(cols()==b.rows()
173 &&
"IncompleteLUT::solve(): invalid number of rows of the right hand side matrix b");
181 inline bool operator() (
const Index& row,
const Index& col,
const Scalar&)
const 190 RealScalar m_droptol;
193 bool m_factorizationIsOk;
194 bool m_isInitialized;
204 template<
typename Scalar>
207 this->m_droptol = droptol;
214 template<
typename Scalar>
217 this->m_fillfactor = fillfactor;
220 template <
typename Scalar>
221 template<
typename _MatrixType>
227 #ifndef EIGEN_MPL2_ONLY 236 m_Pinv = m_P.inverse();
241 ordering(mat1,m_Pinv);
242 m_P = m_Pinv.inverse();
245 m_analysisIsOk =
true;
246 m_factorizationIsOk =
false;
247 m_isInitialized =
false;
250 template <
typename Scalar>
251 template<
typename _MatrixType>
258 eigen_assert((amat.rows() == amat.cols()) &&
"The factorization should be done on a square matrix");
259 Index n = amat.cols();
267 eigen_assert(m_analysisIsOk &&
"You must first call analyzePattern()");
277 Index fill_in =
static_cast<Index
> (amat.nonZeros()*m_fillfactor)/n+1;
278 if (fill_in > n) fill_in = n;
281 Index nnzL = fill_in/2;
283 m_lu.reserve(n * (nnzL + nnzU + 1));
286 for (Index ii = 0; ii < n; ii++)
295 RealScalar rownorm = 0;
297 typename FactorType::InnerIterator j_it(mat, ii);
300 Index k = j_it.index();
305 u(sizel) = j_it.value();
311 u(ii) = j_it.value();
316 Index jpos = ii + sizeu;
318 u(jpos) = j_it.value();
322 rownorm += numext::abs2(j_it.value());
332 rownorm = sqrt(rownorm);
342 Index minrow = ju.segment(jj,sizel-jj).minCoeff(&k);
344 if (minrow != ju(jj))
349 jr(minrow) = jj; jr(j) = k;
356 typename FactorType::InnerIterator ki_it(m_lu, minrow);
357 while (ki_it && ki_it.index() < minrow) ++ki_it;
358 eigen_internal_assert(ki_it && ki_it.col()==minrow);
359 Scalar fact = u(jj) / ki_it.value();
362 if(abs(fact) <= m_droptol)
370 for (; ki_it; ++ki_it)
372 Scalar prod = fact * ki_it.value();
373 Index j = ki_it.index();
382 eigen_internal_assert(sizeu<=n);
388 eigen_internal_assert(sizel<=ii);
406 for(Index k = 0; k <sizeu; k++) jr(ju(ii+k)) = -1;
412 len = (std::min)(sizel, nnzL);
413 typename Vector::SegmentReturnType ul(u.segment(0, sizel));
414 typename VectorXi::SegmentReturnType jul(ju.segment(0, sizel));
415 internal::QuickSplit(ul, jul, len);
419 for(Index k = 0; k < len; k++)
420 m_lu.insertBackByOuterInnerUnordered(ii,ju(k)) = u(k);
425 u(ii) = sqrt(m_droptol) * rownorm;
426 m_lu.insertBackByOuterInnerUnordered(ii, ii) = u(ii);
431 for(Index k = 1; k < sizeu; k++)
433 if(abs(u(ii+k)) > m_droptol * rownorm )
436 u(ii + len) = u(ii + k);
437 ju(ii + len) = ju(ii + k);
441 len = (std::min)(sizeu, nnzU);
442 typename Vector::SegmentReturnType uu(u.segment(ii+1, sizeu-1));
443 typename VectorXi::SegmentReturnType juu(ju.segment(ii+1, sizeu-1));
444 internal::QuickSplit(uu, juu, len);
447 for(Index k = ii + 1; k < ii + len; k++)
448 m_lu.insertBackByOuterInnerUnordered(ii,ju(k)) = u(k);
452 m_lu.makeCompressed();
454 m_factorizationIsOk =
true;
455 m_isInitialized = m_factorizationIsOk;
461 template<
typename _MatrixType,
typename Rhs>
466 EIGEN_MAKE_SOLVE_HELPERS(Dec,Rhs)
468 template<
typename Dest>
void evalTo(Dest& dst)
const 470 dec()._solve(rhs(),dst);
478 #endif // EIGEN_INCOMPLETE_LUT_H Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
Definition: FlexibleKalmanBase.h:98
Definition: ForwardDeclarations.h:124
Functor computing the approximate minimum degree ordering If the matrix is not structurally symmetric...
Definition: Ordering.h:51
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Functor computing the column approximate minimum degree ordering The matrix should be in column-major...
Definition: Ordering.h:115
void setDroptol(const RealScalar &droptol)
Set control parameter droptol.
Definition: IncompleteLUT.h:205
keeps off-diagonal entries; drops diagonal entries
Definition: IncompleteLUT.h:180
void setFillfactor(int fillfactor)
Set control parameter fillfactor.
Definition: IncompleteLUT.h:215
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: IncompleteLUT.h:131
The provided data did not satisfy the prerequisites.
Definition: Constants.h:378
IncompleteLUT< Scalar > & compute(const MatrixType &amat)
Compute an incomplete LU factorization with dual threshold on the matrix mat No pivoting is done in t...
Definition: IncompleteLUT.h:149
Incomplete LU factorization with dual-threshold strategy.
Definition: IncompleteLUT.h:96
Computation was successful.
Definition: Constants.h:376
Definition: BandTriangularSolver.h:13
Definition: ForwardDeclarations.h:125
ComputationInfo
Enum for reporting the status of a computation.
Definition: Constants.h:374
SparseSymmetricPermutationProduct< Derived, Upper|Lower > twistedBy(const PermutationMatrix< Dynamic, Dynamic, Index > &perm) const
Definition: SparseMatrixBase.h:372
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48