67 #ifndef GMM_MODIFIED_GRAM_SCHMIDT_H
68 #define GMM_MODIFIED_GRAM_SCHMIDT_H
75 class modified_gram_schmidt {
77 typedef dense_matrix<T> MAT;
82 modified_gram_schmidt(
int restart,
size_t s) : M(s, restart+1) {}
84 typename linalg_traits<MAT>::const_sub_col_type
85 operator[](
size_t i)
const {
return mat_const_col(M, i); }
87 typename linalg_traits<MAT>::sub_col_type
88 operator[](
size_t i) {
return mat_col(M, i); }
90 inline size_type nrows(
void)
const {
return M.nrows(); }
91 inline size_type ncols(
void)
const {
return M.ncols(); }
92 MAT &mat(
void) {
return M; }
93 const MAT &mat(
void)
const {
return M; }
97 template <
typename T,
typename VecHi>
inline
98 void orthogonalize(modified_gram_schmidt<T>& V,
const VecHi& Hi_,
size_t i) {
99 VecHi& Hi =
const_cast<VecHi&
>(Hi_);
101 for (
size_t k = 0; k <= i; k++) {
102 Hi[k] = gmm::vect_hp(V[i+1], V[k]);
103 gmm::add(gmm::scaled(V[k], -Hi[k]), V[i+1]);
107 template <
typename T,
typename VecHi>
108 void orthogonalize_with_refinment(modified_gram_schmidt<T>& V,
109 const VecHi& Hi_,
size_t i) {
110 VecHi& Hi =
const_cast<VecHi&
>(Hi_);
111 orthogonalize(V, Hi_, i);
113 sub_interval SUBI(0, V.nrows()), SUBJ(0, i+1);
114 std::vector<T> corr(i+1);
115 gmm::mult(
conjugated(sub_matrix(V.mat(), SUBI, SUBJ)),
117 gmm::mult(sub_matrix(V.mat(), SUBI, SUBJ),
118 scaled(corr, T(-1)), V[i+1],V[i+1]);
119 gmm::add(corr, sub_vector(Hi, SUBJ));
122 template <
typename T,
typename VecS,
typename VecX>
123 void combine(modified_gram_schmidt<T>& V,
const VecS& s, VecX& x,
size_t i)
124 {
for (
size_t j = 0; j < i; ++j) gmm::add(gmm::scaled(V[j], s[j]), x); }