File indexing completed on 2025-01-18 09:57:06
0001 namespace Eigen {
0002
0003 namespace internal {
0004
0005 template <typename Scalar>
0006 void r1updt(
0007 Matrix< Scalar, Dynamic, Dynamic > &s,
0008 const Matrix< Scalar, Dynamic, 1> &u,
0009 std::vector<JacobiRotation<Scalar> > &v_givens,
0010 std::vector<JacobiRotation<Scalar> > &w_givens,
0011 Matrix< Scalar, Dynamic, 1> &v,
0012 Matrix< Scalar, Dynamic, 1> &w,
0013 bool *sing)
0014 {
0015 typedef DenseIndex Index;
0016 const JacobiRotation<Scalar> IdentityRotation = JacobiRotation<Scalar>(1,0);
0017
0018
0019 const Index m = s.rows();
0020 const Index n = s.cols();
0021 Index i, j=1;
0022 Scalar temp;
0023 JacobiRotation<Scalar> givens;
0024
0025
0026
0027 eigen_assert(m==n);
0028 eigen_assert(u.size()==m);
0029 eigen_assert(v.size()==n);
0030 eigen_assert(w.size()==n);
0031
0032
0033 w[n-1] = s(n-1,n-1);
0034
0035
0036
0037 for (j=n-2; j>=0; --j) {
0038 w[j] = 0.;
0039 if (v[j] != 0.) {
0040
0041
0042 givens.makeGivens(-v[n-1], v[j]);
0043
0044
0045
0046 v[n-1] = givens.s() * v[j] + givens.c() * v[n-1];
0047 v_givens[j] = givens;
0048
0049
0050 for (i = j; i < m; ++i) {
0051 temp = givens.c() * s(j,i) - givens.s() * w[i];
0052 w[i] = givens.s() * s(j,i) + givens.c() * w[i];
0053 s(j,i) = temp;
0054 }
0055 } else
0056 v_givens[j] = IdentityRotation;
0057 }
0058
0059
0060 w += v[n-1] * u;
0061
0062
0063 *sing = false;
0064 for (j = 0; j < n-1; ++j) {
0065 if (w[j] != 0.) {
0066
0067
0068 givens.makeGivens(-s(j,j), w[j]);
0069
0070
0071 for (i = j; i < m; ++i) {
0072 temp = givens.c() * s(j,i) + givens.s() * w[i];
0073 w[i] = -givens.s() * s(j,i) + givens.c() * w[i];
0074 s(j,i) = temp;
0075 }
0076
0077
0078
0079 w_givens[j] = givens;
0080 } else
0081 v_givens[j] = IdentityRotation;
0082
0083
0084 if (s(j,j) == 0.) {
0085 *sing = true;
0086 }
0087 }
0088
0089 s(n-1,n-1) = w[n-1];
0090
0091 if (s(j,j) == 0.) {
0092 *sing = true;
0093 }
0094 return;
0095 }
0096
0097 }
0098
0099 }