r1updt.h
Go to the documentation of this file.
2 
3 namespace Eigen {
4 
5 namespace internal {
6 
7 template <typename Scalar>
8 void r1updt(
11  std::vector<JacobiRotation<Scalar> > &v_givens,
12  std::vector<JacobiRotation<Scalar> > &w_givens,
15  bool *sing)
16 {
17  typedef DenseIndex Index;
18  const JacobiRotation<Scalar> IdentityRotation = JacobiRotation<Scalar>(1,0);
19 
20  /* Local variables */
21  const Index m = s.rows();
22  const Index n = s.cols();
23  Index i, j=1;
24  Scalar temp;
26 
27  // r1updt had a broader usecase, but we don't use it here. And, more
28  // importantly, we can not test it.
29  eigen_assert(m==n);
30  eigen_assert(u.size()==m);
31  eigen_assert(v.size()==n);
32  eigen_assert(w.size()==n);
33 
34  /* move the nontrivial part of the last column of s into w. */
35  w[n-1] = s(n-1,n-1);
36 
37  /* rotate the vector v into a multiple of the n-th unit vector */
38  /* in such a way that a spike is introduced into w. */
39  for (j=n-2; j>=0; --j) {
40  w[j] = 0.;
41  if (v[j] != 0.) {
42  /* determine a givens rotation which eliminates the */
43  /* j-th element of v. */
44  givens.makeGivens(-v[n-1], v[j]);
45 
46  /* apply the transformation to v and store the information */
47  /* necessary to recover the givens rotation. */
48  v[n-1] = givens.s() * v[j] + givens.c() * v[n-1];
49  v_givens[j] = givens;
50 
51  /* apply the transformation to s and extend the spike in w. */
52  for (i = j; i < m; ++i) {
53  temp = givens.c() * s(j,i) - givens.s() * w[i];
54  w[i] = givens.s() * s(j,i) + givens.c() * w[i];
55  s(j,i) = temp;
56  }
57  } else
58  v_givens[j] = IdentityRotation;
59  }
60 
61  /* add the spike from the rank 1 update to w. */
62  w += v[n-1] * u;
63 
64  /* eliminate the spike. */
65  *sing = false;
66  for (j = 0; j < n-1; ++j) {
67  if (w[j] != 0.) {
68  /* determine a givens rotation which eliminates the */
69  /* j-th element of the spike. */
70  givens.makeGivens(-s(j,j), w[j]);
71 
72  /* apply the transformation to s and reduce the spike in w. */
73  for (i = j; i < m; ++i) {
74  temp = givens.c() * s(j,i) + givens.s() * w[i];
75  w[i] = -givens.s() * s(j,i) + givens.c() * w[i];
76  s(j,i) = temp;
77  }
78 
79  /* store the information necessary to recover the */
80  /* givens rotation. */
81  w_givens[j] = givens;
82  } else
83  v_givens[j] = IdentityRotation;
84 
85  /* test for zero diagonal elements in the output s. */
86  if (s(j,j) == 0.) {
87  *sing = true;
88  }
89  }
90  /* move w back into the last column of the output s. */
91  s(n-1,n-1) = w[n-1];
92 
93  if (s(j,j) == 0.) {
94  *sing = true;
95  }
96  return;
97 }
98 
99 } // end namespace internal
100 
101 } // end namespace Eigen
Matrix3f m
Array< int, Dynamic, 1 > v
int n
int i
#define eigen_assert(x)
RowVector3d w
void makeGivens(const Scalar &p, const Scalar &q, Scalar *r=0)
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
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:8
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
std::ptrdiff_t j