15{
16 const Eigen::Index n = K.rows();
17 const Eigen::Index cap =
18 max_rank > 0 ? std::min<Eigen::Index>(max_rank, n) : n;
19
20
21
22
23
24
25 Eigen::VectorXd d = K.diagonal();
26 const double trace0 = d.sum();
27 const double stop = rtol * (trace0 > 0.0 ? trace0 : 1.0);
28
29 Eigen::MatrixXd L(n, cap);
30 Eigen::Index r = 0;
31 for (; r < cap; ++r) {
32 Eigen::Index j = 0;
33 const double dmax = d.maxCoeff(&j);
34 if (!(dmax > stop)) break;
35
36 Eigen::VectorXd col = K.col(j);
37 if (r > 0)
38 col.noalias() -= L.leftCols(r) * L.row(j).head(r).transpose();
39 const double piv = std::sqrt(dmax);
40 L.col(r) = col / piv;
41
42 d.noalias() -= L.col(r).cwiseAbs2();
43 d = d.cwiseMax(0.0);
44 }
45 L_ = L.leftCols(r);
46}