r1updt.h
Go to the documentation of this file.
1 // IWYU pragma: private
3 
4 namespace Eigen {
5 
6 namespace internal {
7 
8 template <typename Scalar>
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;
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  v_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
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define eigen_assert(x)
Definition: Macros.h:910
RowVector3d w
Definition: Matrix_resize_int.cpp:3
SCALAR Scalar
Definition: bench_gemm.cpp:45
Rotation given by a cosine-sine pair.
Definition: Jacobi.h:38
EIGEN_DEVICE_FUNC Scalar & s()
Definition: Jacobi.h:50
EIGEN_DEVICE_FUNC void makeGivens(const Scalar &p, const Scalar &q, Scalar *r=0)
Definition: Jacobi.h:152
EIGEN_DEVICE_FUNC Scalar & c()
Definition: Jacobi.h:48
RealScalar s
Definition: level1_cplx_impl.h:130
int * m
Definition: level2_cplx_impl.h:294
void r1updt(Matrix< Scalar, Dynamic, Dynamic > &s, const Matrix< Scalar, Dynamic, 1 > &u, std::vector< JacobiRotation< Scalar > > &v_givens, std::vector< JacobiRotation< Scalar > > &w_givens, Matrix< Scalar, Dynamic, 1 > &v, Matrix< Scalar, Dynamic, 1 > &w, bool *sing)
Definition: r1updt.h:9
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: Meta.h:75
Definition: Eigen_Colamd.h:49
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2