use PlanarRotation<> instead of handmade givens rotation in cminpack code

+ cleaning.
This results in some more memory being used, but not much.
This commit is contained in:
Thomas Capricelli
2010-01-26 17:40:55 +01:00
parent c04a93df31
commit afb9bf6281
5 changed files with 78 additions and 147 deletions

View File

@@ -2,46 +2,21 @@
// TODO : move this to GivensQR once there's such a thing in Eigen
template <typename Scalar>
void ei_r1mpyq(int m, int n, Scalar *a, const Scalar *v, const Scalar *w)
void ei_r1mpyq(int m, int n, Scalar *a, const std::vector<PlanarRotation<Scalar> > &v_givens, const std::vector<PlanarRotation<Scalar> > &w_givens)
{
/* Local variables */
int i, j;
Scalar cos__=0., sin__=0., temp;
/* Function Body */
if (n<=1)
return;
/* apply the first set of givens rotations to a. */
for (j = n-2; j>=0; --j) {
if (ei_abs(v[j]) > 1.) {
cos__ = 1. / v[j];
sin__ = ei_sqrt(1. - ei_abs2(cos__));
} else {
sin__ = v[j];
cos__ = ei_sqrt(1. - ei_abs2(sin__));
}
for (i = 0; i<m; ++i) {
temp = cos__ * a[i+m*j] - sin__ * a[i+m*(n-1)];
a[i+m*(n-1)] = sin__ * a[i+m*j] + cos__ * a[i+m*(n-1)];
for (int j = n-2; j>=0; --j)
for (int i = 0; i<m; ++i) {
Scalar temp = v_givens[j].c() * a[i+m*j] - v_givens[j].s() * a[i+m*(n-1)];
a[i+m*(n-1)] = v_givens[j].s() * a[i+m*j] + v_givens[j].c() * a[i+m*(n-1)];
a[i+m*j] = temp;
}
}
/* apply the second set of givens rotations to a. */
for (j = 0; j<n-1; ++j) {
if (ei_abs(w[j]) > 1.) {
cos__ = 1. / w[j];
sin__ = ei_sqrt(1. - ei_abs2(cos__));
} else {
sin__ = w[j];
cos__ = ei_sqrt(1. - ei_abs2(sin__));
}
for (i = 0; i<m; ++i) {
temp = cos__ * a[i+m*j] + sin__ * a[i+m*(n-1)];
a[i+m*(n-1)] = -sin__ * a[i+m*j] + cos__ * a[i+m*(n-1)];
for (int j = 0; j<n-1; ++j)
for (int i = 0; i<m; ++i) {
Scalar temp = w_givens[j].c() * a[i+m*j] + w_givens[j].s() * a[i+m*(n-1)];
a[i+m*(n-1)] = -w_givens[j].s() * a[i+m*j] + w_givens[j].c() * a[i+m*(n-1)];
a[i+m*j] = temp;
}
}
return;
}