Eigen-unsupported  5.0.1-dev+284dcc12
 
Loading...
Searching...
No Matches
covar.h
1// IWYU pragma: private
2#include "./InternalHeaderCheck.h"
3
4namespace Eigen {
5
6namespace internal {
7
8template <typename Scalar>
9void covar(Matrix<Scalar, Dynamic, Dynamic> &r, const VectorXi &ipvt,
10 Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon())) {
11 using std::abs;
12 typedef DenseIndex Index;
13
14 /* Local variables */
15 Index i, j, k, l, ii, jj;
16 bool sing;
17 Scalar temp;
18
19 /* Function Body */
20 const Index n = r.cols();
21 const Scalar tolr = tol * abs(r(0, 0));
22 Matrix<Scalar, Dynamic, 1> wa(n);
23 eigen_assert(ipvt.size() == n);
24
25 /* form the inverse of r in the full upper triangle of r. */
26 l = -1;
27 for (k = 0; k < n; ++k)
28 if (abs(r(k, k)) > tolr) {
29 r(k, k) = 1. / r(k, k);
30 for (j = 0; j <= k - 1; ++j) {
31 temp = r(k, k) * r(j, k);
32 r(j, k) = 0.;
33 r.col(k).head(j + 1) -= r.col(j).head(j + 1) * temp;
34 }
35 l = k;
36 }
37
38 /* form the full upper triangle of the inverse of (r transpose)*r */
39 /* in the full upper triangle of r. */
40 for (k = 0; k <= l; ++k) {
41 for (j = 0; j <= k - 1; ++j) r.col(j).head(j + 1) += r.col(k).head(j + 1) * r(j, k);
42 r.col(k).head(k + 1) *= r(k, k);
43 }
44
45 /* form the full lower triangle of the covariance matrix */
46 /* in the strict lower triangle of r and in wa. */
47 for (j = 0; j < n; ++j) {
48 jj = ipvt[j];
49 sing = j > l;
50 for (i = 0; i <= j; ++i) {
51 if (sing) r(i, j) = 0.;
52 ii = ipvt[i];
53 if (ii > jj) r(ii, jj) = r(i, j);
54 if (ii < jj) r(jj, ii) = r(i, j);
55 }
56 wa[jj] = r(j, j);
57 }
58
59 /* symmetrize the covariance matrix in r. */
60 r.topLeftCorner(n, n).template triangularView<StrictlyUpper>() = r.topLeftCorner(n, n).transpose();
61 r.diagonal() = wa;
62}
63
64} // end namespace internal
65
66} // end namespace Eigen
Matrix< int, Dynamic, 1 > VectorXi
Namespace containing all symbols from the Eigen library.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index