$darkmode
Eigen-unsupported  5.0.1-dev
r1updt.h
1 // IWYU pragma: private
2 #include "./InternalHeaderCheck.h"
3 
4 namespace Eigen {
5 
6 namespace internal {
7 
8 template <typename Scalar>
9 void r1updt(Matrix<Scalar, Dynamic, Dynamic> &s, const Matrix<Scalar, Dynamic, 1> &u,
10  std::vector<JacobiRotation<Scalar> > &v_givens, std::vector<JacobiRotation<Scalar> > &w_givens,
12  typedef DenseIndex Index;
13  const JacobiRotation<Scalar> IdentityRotation = JacobiRotation<Scalar>(1, 0);
14 
15  /* Local variables */
16  const Index m = s.rows();
17  const Index n = s.cols();
18  Index i, j = 1;
19  Scalar temp;
20  JacobiRotation<Scalar> givens;
21 
22  // r1updt had a broader usecase, but we don't use it here. And, more
23  // importantly, we can not test it.
24  eigen_assert(m == n);
25  eigen_assert(u.size() == m);
26  eigen_assert(v.size() == n);
27  eigen_assert(w.size() == n);
28 
29  /* move the nontrivial part of the last column of s into w. */
30  w[n - 1] = s(n - 1, n - 1);
31 
32  /* rotate the vector v into a multiple of the n-th unit vector */
33  /* in such a way that a spike is introduced into w. */
34  for (j = n - 2; j >= 0; --j) {
35  w[j] = 0.;
36  if (v[j] != 0.) {
37  /* determine a givens rotation which eliminates the */
38  /* j-th element of v. */
39  givens.makeGivens(-v[n - 1], v[j]);
40 
41  /* apply the transformation to v and store the information */
42  /* necessary to recover the givens rotation. */
43  v[n - 1] = givens.s() * v[j] + givens.c() * v[n - 1];
44  v_givens[j] = givens;
45 
46  /* apply the transformation to s and extend the spike in w. */
47  for (i = j; i < m; ++i) {
48  temp = givens.c() * s(j, i) - givens.s() * w[i];
49  w[i] = givens.s() * s(j, i) + givens.c() * w[i];
50  s(j, i) = temp;
51  }
52  } else
53  v_givens[j] = IdentityRotation;
54  }
55 
56  /* add the spike from the rank 1 update to w. */
57  w += v[n - 1] * u;
58 
59  /* eliminate the spike. */
60  *sing = false;
61  for (j = 0; j < n - 1; ++j) {
62  if (w[j] != 0.) {
63  /* determine a givens rotation which eliminates the */
64  /* j-th element of the spike. */
65  givens.makeGivens(-s(j, j), w[j]);
66 
67  /* apply the transformation to s and reduce the spike in w. */
68  for (i = j; i < m; ++i) {
69  temp = givens.c() * s(j, i) + givens.s() * w[i];
70  w[i] = -givens.s() * s(j, i) + givens.c() * w[i];
71  s(j, i) = temp;
72  }
73 
74  /* store the information necessary to recover the */
75  /* givens rotation. */
76  w_givens[j] = givens;
77  } else
78  w_givens[j] = IdentityRotation;
79 
80  /* test for zero diagonal elements in the output s. */
81  if (s(j, j) == 0.) {
82  *sing = true;
83  }
84  }
85  /* move w back into the last column of the output s. */
86  s(n - 1, n - 1) = w[n - 1];
87 
88  if (s(j, j) == 0.) {
89  *sing = true;
90  }
91  return;
92 }
93 
94 } // end namespace internal
95 
96 } // end namespace Eigen
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index