11 #ifndef EIGEN_INCOMPLETE_LUT_H 12 #define EIGEN_INCOMPLETE_LUT_H 28 template <
typename VectorV,
typename VectorI>
29 Index QuickSplit(VectorV &row, VectorI &ind,
Index ncut)
31 typedef typename VectorV::RealScalar RealScalar;
41 if (ncut < first || ncut > last )
return 0;
45 RealScalar abskey = abs(row(mid));
46 for (
Index j = first + 1; j <= last; j++) {
47 if ( abs(row(j)) > abskey) {
49 swap(row(mid), row(j));
50 swap(ind(mid), ind(j));
54 swap(row(mid), row(first));
55 swap(ind(mid), ind(first));
57 if (mid > ncut) last = mid - 1;
58 else if (mid < ncut ) first = mid + 1;
59 }
while (mid != ncut );
98 template <
typename _Scalar,
typename _StorageIndex =
int>
103 using Base::m_isInitialized;
105 typedef _Scalar Scalar;
106 typedef _StorageIndex StorageIndex;
121 m_analysisIsOk(
false), m_factorizationIsOk(
false)
124 template<
typename MatrixType>
126 : m_droptol(droptol),m_fillfactor(fillfactor),
127 m_analysisIsOk(
false),m_factorizationIsOk(
false)
129 eigen_assert(fillfactor != 0);
133 Index rows()
const {
return m_lu.rows(); }
135 Index cols()
const {
return m_lu.cols(); }
144 eigen_assert(m_isInitialized &&
"IncompleteLUT is not initialized.");
148 template<
typename MatrixType>
149 void analyzePattern(
const MatrixType& amat);
151 template<
typename MatrixType>
152 void factorize(
const MatrixType& amat);
159 template<
typename MatrixType>
162 analyzePattern(amat);
167 void setDroptol(
const RealScalar& droptol);
168 void setFillfactor(
int fillfactor);
170 template<
typename Rhs,
typename Dest>
171 void _solve_impl(
const Rhs& b, Dest& x)
const 174 x = m_lu.template triangularView<UnitLower>().solve(x);
175 x = m_lu.template triangularView<Upper>().solve(x);
183 inline bool operator() (
const Index& row,
const Index& col,
const Scalar&)
const 192 RealScalar m_droptol;
195 bool m_factorizationIsOk;
205 template<
typename Scalar,
typename StorageIndex>
208 this->m_droptol = droptol;
215 template<
typename Scalar,
typename StorageIndex>
218 this->m_fillfactor = fillfactor;
221 template <
typename Scalar,
typename StorageIndex>
222 template<
typename _MatrixType>
228 #ifndef EIGEN_MPL2_ONLY 237 m_Pinv = m_P.inverse();
242 ordering(mat1,m_Pinv);
243 m_P = m_Pinv.inverse();
246 m_analysisIsOk =
true;
247 m_factorizationIsOk =
false;
248 m_isInitialized =
true;
251 template <
typename Scalar,
typename StorageIndex>
252 template<
typename _MatrixType>
258 using internal::convert_index;
260 eigen_assert((amat.rows() == amat.cols()) &&
"The factorization should be done on a square matrix");
261 Index n = amat.cols();
269 eigen_assert(m_analysisIsOk &&
"You must first call analyzePattern()");
279 Index fill_in = (amat.nonZeros()*m_fillfactor)/n + 1;
280 if (fill_in > n) fill_in = n;
283 Index nnzL = fill_in/2;
285 m_lu.reserve(n * (nnzL + nnzU + 1));
288 for (
Index ii = 0; ii < n; ii++)
294 ju(ii) = convert_index<StorageIndex>(ii);
296 jr(ii) = convert_index<StorageIndex>(ii);
297 RealScalar rownorm = 0;
299 typename FactorType::InnerIterator j_it(mat, ii);
302 Index k = j_it.index();
306 ju(sizel) = convert_index<StorageIndex>(k);
307 u(sizel) = j_it.value();
308 jr(k) = convert_index<StorageIndex>(sizel);
313 u(ii) = j_it.value();
318 Index jpos = ii + sizeu;
319 ju(jpos) = convert_index<StorageIndex>(k);
320 u(jpos) = j_it.value();
321 jr(k) = convert_index<StorageIndex>(jpos);
324 rownorm += numext::abs2(j_it.value());
334 rownorm = sqrt(rownorm);
344 Index minrow = ju.segment(jj,sizel-jj).minCoeff(&k);
346 if (minrow != ju(jj))
351 jr(minrow) = convert_index<StorageIndex>(jj);
352 jr(j) = convert_index<StorageIndex>(k);
359 typename FactorType::InnerIterator ki_it(m_lu, minrow);
360 while (ki_it && ki_it.index() < minrow) ++ki_it;
361 eigen_internal_assert(ki_it && ki_it.col()==minrow);
362 Scalar fact = u(jj) / ki_it.value();
365 if(abs(fact) <= m_droptol)
373 for (; ki_it; ++ki_it)
375 Scalar prod = fact * ki_it.value();
376 Index j = ki_it.index();
385 eigen_internal_assert(sizeu<=n);
391 eigen_internal_assert(sizel<=ii);
393 ju(newpos) = convert_index<StorageIndex>(j);
395 jr(j) = convert_index<StorageIndex>(newpos);
402 ju(len) = convert_index<StorageIndex>(minrow);
409 for(
Index k = 0; k <sizeu; k++) jr(ju(ii+k)) = -1;
415 len = (std::min)(sizel, nnzL);
416 typename Vector::SegmentReturnType ul(u.segment(0, sizel));
417 typename VectorI::SegmentReturnType jul(ju.segment(0, sizel));
418 internal::QuickSplit(ul, jul, len);
422 for(
Index k = 0; k < len; k++)
423 m_lu.insertBackByOuterInnerUnordered(ii,ju(k)) = u(k);
427 if (u(ii) == Scalar(0))
428 u(ii) = sqrt(m_droptol) * rownorm;
429 m_lu.insertBackByOuterInnerUnordered(ii, ii) = u(ii);
434 for(
Index k = 1; k < sizeu; k++)
436 if(abs(u(ii+k)) > m_droptol * rownorm )
439 u(ii + len) = u(ii + k);
440 ju(ii + len) = ju(ii + k);
444 len = (std::min)(sizeu, nnzU);
445 typename Vector::SegmentReturnType uu(u.segment(ii+1, sizeu-1));
446 typename VectorI::SegmentReturnType juu(ju.segment(ii+1, sizeu-1));
447 internal::QuickSplit(uu, juu, len);
450 for(
Index k = ii + 1; k < ii + len; k++)
451 m_lu.insertBackByOuterInnerUnordered(ii,ju(k)) = u(k);
454 m_lu.makeCompressed();
456 m_factorizationIsOk =
true;
462 #endif // EIGEN_INCOMPLETE_LUT_H ComputationInfo info() const
Reports whether previous computation was successful.
Definition: IncompleteLUT.h:142
void setDroptol(const RealScalar &droptol)
Set control parameter droptol.
Definition: IncompleteLUT.h:206
A base class for sparse solvers.
Definition: SparseSolverBase.h:67
Functor computing the approximate minimum degree ordering If the matrix is not structurally symmetric...
Definition: Ordering.h:52
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
Definition: Ordering.h:118
keeps off-diagonal entries; drops diagonal entries
Definition: IncompleteLUT.h:182
The provided data did not satisfy the prerequisites.
Definition: Constants.h:434
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Incomplete LU factorization with dual-threshold strategy.
Definition: IncompleteLUT.h:99
Computation was successful.
Definition: Constants.h:432
Definition: BandTriangularSolver.h:13
SparseSymmetricPermutationProduct< Derived, Upper|Lower > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
Definition: SparseMatrixBase.h:315
IncompleteLUT & 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:160
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
ComputationInfo
Enum for reporting the status of a computation.
Definition: Constants.h:430
void setFillfactor(int fillfactor)
Set control parameter fillfactor.
Definition: IncompleteLUT.h:216