File indexing completed on 2025-01-18 09:57:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef EIGEN_LMCOVAR_H
0013 #define EIGEN_LMCOVAR_H
0014
0015 namespace Eigen {
0016
0017 namespace internal {
0018
0019 template <typename Scalar>
0020 void covar(
0021 Matrix< Scalar, Dynamic, Dynamic > &r,
0022 const VectorXi& ipvt,
0023 Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) )
0024 {
0025 using std::abs;
0026
0027 Index i, j, k, l, ii, jj;
0028 bool sing;
0029 Scalar temp;
0030
0031
0032 const Index n = r.cols();
0033 const Scalar tolr = tol * abs(r(0,0));
0034 Matrix< Scalar, Dynamic, 1 > wa(n);
0035 eigen_assert(ipvt.size()==n);
0036
0037
0038 l = -1;
0039 for (k = 0; k < n; ++k)
0040 if (abs(r(k,k)) > tolr) {
0041 r(k,k) = 1. / r(k,k);
0042 for (j = 0; j <= k-1; ++j) {
0043 temp = r(k,k) * r(j,k);
0044 r(j,k) = 0.;
0045 r.col(k).head(j+1) -= r.col(j).head(j+1) * temp;
0046 }
0047 l = k;
0048 }
0049
0050
0051
0052 for (k = 0; k <= l; ++k) {
0053 for (j = 0; j <= k-1; ++j)
0054 r.col(j).head(j+1) += r.col(k).head(j+1) * r(j,k);
0055 r.col(k).head(k+1) *= r(k,k);
0056 }
0057
0058
0059
0060 for (j = 0; j < n; ++j) {
0061 jj = ipvt[j];
0062 sing = j > l;
0063 for (i = 0; i <= j; ++i) {
0064 if (sing)
0065 r(i,j) = 0.;
0066 ii = ipvt[i];
0067 if (ii > jj)
0068 r(ii,jj) = r(i,j);
0069 if (ii < jj)
0070 r(jj,ii) = r(i,j);
0071 }
0072 wa[jj] = r(j,j);
0073 }
0074
0075
0076 r.topLeftCorner(n,n).template triangularView<StrictlyUpper>() = r.topLeftCorner(n,n).transpose();
0077 r.diagonal() = wa;
0078 }
0079
0080 }
0081
0082 }
0083
0084 #endif