44 #include "DenseLinAlgPack_InvCholUpdate.hpp"
45 #include "DenseLinAlgPack_DMatrixClass.hpp"
46 #include "DenseLinAlgPack_DVectorOp.hpp"
50 inline int sign(
double v) {
61 void DenseLinAlgPack::update_chol_factor(DMatrixSlice* pM, DVectorSlice* pu
62 ,
const DVectorSlice& v)
64 DMatrixSlice &M = *pM;
65 DVectorSlice &u = *pu;
68 if(M.rows() != u.dim() || u.dim() != v.dim())
69 throw std::length_error(
"update_chol_factor(): Sizes of matrix and vectors do not match");
79 DVectorSlice::reverse_iterator r_itr_u = u.rbegin();
80 while(*r_itr_u == 0.0 && k > 1) --k;
85 DVectorSlice::reverse_iterator
86 r_itr_u_i = u(1,k-1).rbegin(),
87 r_itr_u_ip1 = u(2,k).rbegin();
88 for(
size_type i = k-1; i > 0 ; ++r_itr_u_i, ++r_itr_u_ip1, --i) {
89 value_type u_i = *r_itr_u_i, u_ip1 = *r_itr_u_ip1;
90 jacobi_rotate(&M, i, u_i, - u_ip1);
91 *r_itr_u_i = (u_i == 0.0) ? ::fabs(u_ip1) : ::sqrt(u_i * u_i + u_ip1 * u_ip1);
96 DenseLinAlgPack::Vp_StV(&M.row(1), u(1), v);
100 DVectorSlice::const_iterator
101 itr_M_i_i = M.diag().begin(),
102 itr_M_ip1_i = M.diag(-1).begin();
104 jacobi_rotate(&M, i, *itr_M_i_i++, - *itr_M_ip1_i++);
153 void DenseLinAlgPack::jacobi_rotate(DMatrixSlice* pM,
size_type row_i, value_type alpha
156 DMatrixSlice &M = *pM;
158 assert_gms_square(M);
169 value_type den = ::sqrt(alpha * alpha + beta * beta);
178 DVectorSlice::iterator
179 itr_M_i = M.row(i)(i,n).begin(),
180 itr_M_i_end = M.row(i)(i,n).end(),
181 itr_M_ip1 = M.row(i+1)(i,n).begin();
183 while(itr_M_i != itr_M_i_end) {
184 value_type y = *itr_M_i, w = *itr_M_ip1;
185 *itr_M_i++ = c * y - s * w;
186 *itr_M_ip1++ = s * y + c * w;