covar.h
Go to the documentation of this file.
2 
3 namespace Eigen {
4 
5 namespace internal {
6 
7 template <typename Scalar>
8 void covar(
10  const VectorXi &ipvt,
11  Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) )
12 {
13  using std::abs;
14  typedef DenseIndex Index;
15 
16  /* Local variables */
17  Index i, j, k, l, ii, jj;
18  bool sing;
19  Scalar temp;
20 
21  /* Function Body */
22  const Index n = r.cols();
23  const Scalar tolr = tol * abs(r(0,0));
25  eigen_assert(ipvt.size()==n);
26 
27  /* form the inverse of r in the full upper triangle of r. */
28  l = -1;
29  for (k = 0; k < n; ++k)
30  if (abs(r(k,k)) > tolr) {
31  r(k,k) = 1. / r(k,k);
32  for (j = 0; j <= k-1; ++j) {
33  temp = r(k,k) * r(j,k);
34  r(j,k) = 0.;
35  r.col(k).head(j+1) -= r.col(j).head(j+1) * temp;
36  }
37  l = k;
38  }
39 
40  /* form the full upper triangle of the inverse of (r transpose)*r */
41  /* in the full upper triangle of r. */
42  for (k = 0; k <= l; ++k) {
43  for (j = 0; j <= k-1; ++j)
44  r.col(j).head(j+1) += r.col(k).head(j+1) * r(j,k);
45  r.col(k).head(k+1) *= r(k,k);
46  }
47 
48  /* form the full lower triangle of the covariance matrix */
49  /* in the strict lower triangle of r and in wa. */
50  for (j = 0; j < n; ++j) {
51  jj = ipvt[j];
52  sing = j > l;
53  for (i = 0; i <= j; ++i) {
54  if (sing)
55  r(i,j) = 0.;
56  ii = ipvt[i];
57  if (ii > jj)
58  r(ii,jj) = r(i,j);
59  if (ii < jj)
60  r(jj,ii) = r(i,j);
61  }
62  wa[jj] = r(j,j);
63  }
64 
65  /* symmetrize the covariance matrix in r. */
66  r.topLeftCorner(n,n).template triangularView<StrictlyUpper>() = r.topLeftCorner(n,n).transpose();
67  r.diagonal() = wa;
68 }
69 
70 } // end namespace internal
71 
72 } // end namespace Eigen
int n
int i
#define eigen_assert(x)
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Matrix< int, Dynamic, 1 > VectorXi
void covar(Matrix< Scalar, Dynamic, Dynamic > &r, const VectorXi &ipvt, Scalar tol=std::sqrt(NumTraits< Scalar >::epsilon()))
Definition: LMcovar.h:22
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Eigen::internal::remove_all_t< DerType >, typename Eigen::internal::traits< Eigen::internal::remove_all_t< DerType >>::Scalar, product) > sqrt(const Eigen::AutoDiffScalar< DerType > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
adouble abs(const adouble &x)
Definition: AdolcForward:74
std::ptrdiff_t j