38 #ifndef GMM_PRECOND_ILDLTT_H 39 #define GMM_PRECOND_ILDLTT_H 50 template <
typename Matrix>
53 typedef typename linalg_traits<Matrix>::value_type value_type;
54 typedef typename number_traits<value_type>::magnitude_type magnitude_type;
58 row_matrix<svector> U;
59 std::vector<magnitude_type> indiag;
65 template<
typename M>
void do_ildltt(
const M&, row_major);
66 void do_ildltt(
const Matrix&, col_major);
69 void build_with(
const Matrix& A,
int k_ = -1,
double eps_ =
double(-1)) {
71 if (eps_ >=
double(0)) eps = eps_;
73 indiag.resize(std::min(mat_nrows(A), mat_ncols(A)));
74 do_ildltt(A,
typename principal_orientation_type<
typename 75 linalg_traits<Matrix>::sub_orientation>::potype());
78 : U(mat_nrows(A),mat_ncols(A)), K(k_), eps(eps_) { build_with(A); }
81 size_type memsize()
const {
82 return sizeof(*this) +
nnz(U)*
sizeof(value_type) + indiag.size() *
sizeof(magnitude_type);
86 template<
typename Matrix>
template<
typename M>
89 typedef typename number_traits<T>::magnitude_type R;
91 size_type n = mat_nrows(A);
95 R prec = default_tol(R()), max_pivot = gmm::abs(A(0,0)) * prec;
98 for (size_type i = 0; i < n; ++i) {
99 gmm::copy(mat_const_row(A, i), w);
102 for (size_type krow = 0, k; krow < w.nb_stored(); ++krow) {
103 typename svector::iterator wk = w.begin() + krow;
104 if ((k = wk->c) >= i)
break;
105 if (gmm::is_complex(wk->e)) {
106 tmp = gmm::conj(U(k, i))/indiag[k];
107 gmm::add(scaled(mat_row(U, k), -tmp), w);
111 if (gmm::abs(tmp) < eps * norm_row) { w.sup(k); --krow; }
112 else { wk->e += tmp; gmm::add(scaled(mat_row(U, k), -tmp), w); }
117 if (gmm::abs(gmm::real(tmp)) <= max_pivot)
118 { GMM_WARNING2(
"pivot " << i <<
" is too small"); tmp = T(1); }
120 max_pivot = std::max(max_pivot, std::min(gmm::abs(tmp) * prec, R(1)));
121 indiag[i] = R(1) / gmm::real(tmp);
122 gmm::clean(w, eps * norm_row);
123 gmm::scale(w, T(indiag[i]));
124 std::sort(w.begin(), w.end(), elt_rsvector_value_less_<T>());
125 typename svector::const_iterator wit = w.begin(), wite = w.end();
126 for (size_type nnu = 0; wit != wite; ++wit)
127 if (wit->c > i) {
if (nnu < K) { U(i, wit->c) = wit->e; ++nnu; } }
131 template<
typename Matrix>
135 template <
typename Matrix,
typename V1,
typename V2>
inline 139 for (size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
140 gmm::upper_tri_solve(P.U, v2,
true);
143 template <
typename Matrix,
typename V1,
typename V2>
inline 147 template <
typename Matrix,
typename V1,
typename V2>
inline 151 for (size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
154 template <
typename Matrix,
typename V1,
typename V2>
inline 156 {
copy(v1, v2); gmm::upper_tri_solve(P.U, v2,
true); }
158 template <
typename Matrix,
typename V1,
typename V2>
inline 162 gmm::upper_tri_solve(P.U, v2,
true);
163 for (size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
166 template <
typename Matrix,
typename V1,
typename V2>
inline number_traits< typename linalg_traits< V >::value_type >::magnitude_type vect_norm2(const V &v)
Euclidean norm of a vector.
incomplete LDL^t (cholesky) preconditioner with fill-in and threshold.
conjugated_return< L >::return_type conjugated(const L &v)
return a conjugated view of the input matrix or vector.
void copy(const L1 &l1, L2 &l2)
*/
sparse vector built upon std::vector.
void clear(L &l)
clear (fill with zeros) a vector or matrix.
ILUT: Incomplete LU with threshold and K fill-in Preconditioner.
void resize(M &v, size_type m, size_type n)
*/
size_type nnz(const L &l)
count the number of non-zero entries of a vector or matrix.