mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
port ei_rwupdt to c++, and misc cleaning
This commit is contained in:
@@ -1,45 +1,41 @@
|
||||
|
||||
template <typename Scalar>
|
||||
void ei_rwupdt(int n, Scalar *r__, int ldr, const Scalar *w, Scalar *b, Scalar alpha)
|
||||
template <typename Scalar>
|
||||
void ei_rwupdt(
|
||||
Matrix< Scalar, Dynamic, Dynamic > &r,
|
||||
const Matrix< Scalar, Dynamic, 1> &w,
|
||||
Matrix< Scalar, Dynamic, 1> &b,
|
||||
Scalar alpha)
|
||||
{
|
||||
const int n = r.cols();
|
||||
assert(r.rows()>=n);
|
||||
std::vector<PlanarRotation<Scalar> > givens(n);
|
||||
/* System generated locals */
|
||||
int r_dim1, r_offset;
|
||||
|
||||
/* Local variables */
|
||||
Scalar temp, rowj;
|
||||
|
||||
/* Parameter adjustments */
|
||||
--b;
|
||||
--w;
|
||||
r_dim1 = ldr;
|
||||
r_offset = 1 + r_dim1 * 1;
|
||||
r__ -= r_offset;
|
||||
|
||||
/* Function Body */
|
||||
for (int j = 1; j <= n; ++j) {
|
||||
for (int j = 0; j < n; ++j) {
|
||||
rowj = 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 = 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;
|
||||
}
|
||||
/* r(i,j), i=0,1,...,j-1, and to w(j). */
|
||||
for (int i = 0; i < j; ++i) {
|
||||
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.)
|
||||
continue;
|
||||
|
||||
/* determine a givens rotation which eliminates w(j). */
|
||||
if (rowj != 0.) {
|
||||
givens[j-1].makeGivens(-r__[j + j * r_dim1], rowj);
|
||||
givens[j].makeGivens(-r(j,j), rowj);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user