File indexing completed on 2025-01-18 09:57:06
0001 namespace Eigen {
0002
0003 namespace internal {
0004
0005
0006 template <typename Scalar>
0007 void qrsolv(
0008 Matrix< Scalar, Dynamic, Dynamic > &s,
0009
0010 const VectorXi &ipvt,
0011 const Matrix< Scalar, Dynamic, 1 > &diag,
0012 const Matrix< Scalar, Dynamic, 1 > &qtb,
0013 Matrix< Scalar, Dynamic, 1 > &x,
0014 Matrix< Scalar, Dynamic, 1 > &sdiag)
0015
0016 {
0017 typedef DenseIndex Index;
0018
0019
0020 Index i, j, k, l;
0021 Scalar temp;
0022 Index n = s.cols();
0023 Matrix< Scalar, Dynamic, 1 > wa(n);
0024 JacobiRotation<Scalar> givens;
0025
0026
0027
0028
0029
0030
0031
0032 x = s.diagonal();
0033 wa = qtb;
0034
0035 s.topLeftCorner(n,n).template triangularView<StrictlyLower>() = s.topLeftCorner(n,n).transpose();
0036
0037
0038 for (j = 0; j < n; ++j) {
0039
0040
0041
0042 l = ipvt[j];
0043 if (diag[l] == 0.)
0044 break;
0045 sdiag.tail(n-j).setZero();
0046 sdiag[j] = diag[l];
0047
0048
0049
0050
0051 Scalar qtbpj = 0.;
0052 for (k = j; k < n; ++k) {
0053
0054
0055 givens.makeGivens(-s(k,k), sdiag[k]);
0056
0057
0058
0059 s(k,k) = givens.c() * s(k,k) + givens.s() * sdiag[k];
0060 temp = givens.c() * wa[k] + givens.s() * qtbpj;
0061 qtbpj = -givens.s() * wa[k] + givens.c() * qtbpj;
0062 wa[k] = temp;
0063
0064
0065 for (i = k+1; i<n; ++i) {
0066 temp = givens.c() * s(i,k) + givens.s() * sdiag[i];
0067 sdiag[i] = -givens.s() * s(i,k) + givens.c() * sdiag[i];
0068 s(i,k) = temp;
0069 }
0070 }
0071 }
0072
0073
0074
0075 Index nsing;
0076 for(nsing=0; nsing<n && sdiag[nsing]!=0; nsing++) {}
0077
0078 wa.tail(n-nsing).setZero();
0079 s.topLeftCorner(nsing, nsing).transpose().template triangularView<Upper>().solveInPlace(wa.head(nsing));
0080
0081
0082 sdiag = s.diagonal();
0083 s.diagonal() = x;
0084
0085
0086 for (j = 0; j < n; ++j) x[ipvt[j]] = wa[j];
0087 }
0088
0089 }
0090
0091 }