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

@@ -1,18 +1,15 @@
template <typename Scalar>
void ei_rwupdt(int n, Scalar *r__, int ldr,
const Scalar *w, Scalar *b, Scalar *alpha, Scalar *cos__,
Scalar *sin__)
template <typename Scalar>
void ei_rwupdt(int n, Scalar *r__, int ldr, const Scalar *w, Scalar *b, Scalar alpha)
{
std::vector<PlanarRotation<Scalar> > givens(n);
/* System generated locals */
int r_dim1, r_offset;
/* Local variables */
Scalar tan__, temp, rowj, cotan;
Scalar temp, rowj;
/* Parameter adjustments */
--sin__;
--cos__;
--b;
--w;
r_dim1 = ldr;
@@ -23,34 +20,23 @@ void ei_rwupdt(int n, Scalar *r__, int ldr,
for (int j = 1; j <= n; ++j) {
rowj = w[j];
/* apply the previous transformations to */
/* r(i,j), i=1,2,...,j-1, and to w(j). */
/* apply the previous transformations to */
/* r(i,j), i=1,2,...,j-1, and to w(j). */
if (j-1>=1)
for (int i = 1; i <= j-1; ++i) {
temp = cos__[i] * r__[i + j * r_dim1] + sin__[i] * rowj;
rowj = -sin__[i] * r__[i + j * r_dim1] + cos__[i] * rowj;
temp = givens[i-1].c() * r__[i + j * r_dim1] + givens[i-1].s() * rowj;
rowj = -givens[i-1].s() * r__[i + j * r_dim1] + givens[i-1].c() * rowj;
r__[i + j * r_dim1] = temp;
}
/* determine a givens rotation which eliminates w(j). */
cos__[j] = 1.;
sin__[j] = 0.;
/* determine a givens rotation which eliminates w(j). */
if (rowj != 0.) {
if (ei_abs(r__[j + j * r_dim1]) < ei_abs(rowj)) {
cotan = r__[j + j * r_dim1] / rowj;
sin__[j] = Scalar(.5) / ei_sqrt(Scalar(0.25) + Scalar(0.25) * ei_abs2(cotan));
cos__[j] = sin__[j] * cotan;
}
else {
tan__ = rowj / r__[j + j * r_dim1];
cos__[j] = Scalar(.5) / ei_sqrt(Scalar(0.25) + Scalar(0.25) * ei_abs2(tan__));
sin__[j] = cos__[j] * tan__;
}
givens[j-1].makeGivens(-r__[j + j * r_dim1], rowj);
/* apply the current transformation to r(j,j), b(j), and alpha. */
r__[j + j * r_dim1] = cos__[j] * r__[j + j * r_dim1] + sin__[j] * rowj;
temp = cos__[j] * b[j] + sin__[j] * *alpha;
*alpha = -sin__[j] * b[j] + cos__[j] * *alpha;
/* apply the current transformation to r(j,j), b(j), and alpha. */
r__[j + j * r_dim1] = givens[j-1].c() * r__[j + j * r_dim1] + givens[j-1].s() * rowj;
temp = givens[j-1].c() * b[j] + givens[j-1].s() * alpha;
alpha = -givens[j-1].s() * b[j] + givens[j-1].c() * alpha;
b[j] = temp;
}
}