aboutsummaryrefslogtreecommitdiff
path: root/unsupported/Eigen/src/NonLinearOptimization/rwupdt.h
blob: 9ce079e22c37d54c731f381cbefa024e4038a826 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace Eigen { 

namespace internal {

template <typename Scalar>
void rwupdt(
        Matrix< Scalar, Dynamic, Dynamic >  &r,
        const Matrix< Scalar, Dynamic, 1>  &w,
        Matrix< Scalar, Dynamic, 1>  &b,
        Scalar alpha)
{
    typedef DenseIndex Index;

    const Index n = r.cols();
    assert(r.rows()>=n);
    std::vector<JacobiRotation<Scalar> > givens(n);

    /* Local variables */
    Scalar temp, rowj;

    /* Function Body */
    for (Index j = 0; j < n; ++j) {
        rowj = w[j];

        /* apply the previous transformations to */
        /* r(i,j), i=0,1,...,j-1, and to w(j). */
        for (Index 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;
        }

        /* determine a givens rotation which eliminates w(j). */
        givens[j].makeGivens(-r(j,j), rowj);

        if (rowj == 0.)
            continue; // givens[j] is identity

        /* 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;
    }
}

} // end namespace internal

} // end namespace Eigen