2009-08-22 06:40:22 +02:00
|
|
|
|
2010-01-27 09:01:13 +01:00
|
|
|
template <typename Scalar>
|
|
|
|
|
void ei_rwupdt(
|
|
|
|
|
Matrix< Scalar, Dynamic, Dynamic > &r,
|
|
|
|
|
const Matrix< Scalar, Dynamic, 1> &w,
|
|
|
|
|
Matrix< Scalar, Dynamic, 1> &b,
|
|
|
|
|
Scalar alpha)
|
2009-08-22 06:40:22 +02:00
|
|
|
{
|
2010-05-30 16:00:58 -04:00
|
|
|
typedef DenseIndex Index;
|
|
|
|
|
|
|
|
|
|
const Index n = r.cols();
|
2010-01-27 09:01:13 +01:00
|
|
|
assert(r.rows()>=n);
|
2010-10-19 21:56:26 -04:00
|
|
|
std::vector<JacobiRotation<Scalar> > givens(n);
|
2009-08-22 06:40:22 +02:00
|
|
|
|
|
|
|
|
/* Local variables */
|
2010-01-26 17:40:55 +01:00
|
|
|
Scalar temp, rowj;
|
2009-08-22 06:40:22 +02:00
|
|
|
|
|
|
|
|
/* Function Body */
|
2010-05-30 16:00:58 -04:00
|
|
|
for (Index j = 0; j < n; ++j) {
|
2010-01-26 13:20:24 +01:00
|
|
|
rowj = w[j];
|
|
|
|
|
|
2010-01-26 17:40:55 +01:00
|
|
|
/* apply the previous transformations to */
|
2010-01-27 09:01:13 +01:00
|
|
|
/* r(i,j), i=0,1,...,j-1, and to w(j). */
|
2010-05-30 16:00:58 -04:00
|
|
|
for (Index i = 0; i < j; ++i) {
|
2010-01-27 09:01:13 +01:00
|
|
|
temp = givens[i].c() * r(i,j) + givens[i].s() * rowj;
|
|
|
|
|
rowj = -givens[i].s() * r(i,j) + givens[i].c() * rowj;
|
|
|
|
|
r(i,j) = temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rowj == 0.)
|
2010-04-17 05:23:23 +02:00
|
|
|
{
|
2010-10-19 21:56:26 -04:00
|
|
|
givens[j] = JacobiRotation<Scalar>(1,0);
|
2010-04-17 05:23:23 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-01-26 13:20:24 +01:00
|
|
|
|
2010-01-26 17:40:55 +01:00
|
|
|
/* determine a givens rotation which eliminates w(j). */
|
2010-01-27 09:01:13 +01:00
|
|
|
givens[j].makeGivens(-r(j,j), rowj);
|
|
|
|
|
|
|
|
|
|
/* apply the current transformation to r(j,j), b(j), and alpha. */
|
|
|
|
|
r(j,j) = givens[j].c() * r(j,j) + givens[j].s() * rowj;
|
|
|
|
|
temp = givens[j].c() * b[j] + givens[j].s() * alpha;
|
|
|
|
|
alpha = -givens[j].s() * b[j] + givens[j].c() * alpha;
|
|
|
|
|
b[j] = temp;
|
2009-08-22 06:40:22 +02:00
|
|
|
}
|
2010-01-26 13:20:24 +01:00
|
|
|
}
|
2009-08-22 06:40:22 +02:00
|
|
|
|