Skip to content

Commit 3366ff4

Browse files
committed
Code simplification suggested by Gael Guennebaud
1 parent d32b93d commit 3366ff4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/fastLm.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ ColPivQR::ColPivQR(const MMatrixXd &X, const MVectorXd &y) : lm(X, y) {
5959
PermutationType Pmat = PQR.colsPermutation();
6060
m_perm = Pmat.indices();
6161
m_r = PQR.rank();
62-
m_df = m_n - m_r;
6362
MatrixXd R = PQR.matrixQR().topLeftCorner(m_p, m_p);
6463

6564
if (m_r < (int)m_p) { // The rank-deficient case
65+
m_df = m_n - m_r;
6666
int nsing = m_p - m_r;
6767
MatrixXd Atrunc = (X * Pmat).leftCols(m_r);
6868
QRType QR(Atrunc);
@@ -129,8 +129,7 @@ MatrixXd pseudoInverse(const MatrixXd& X, double tolerance) {
129129
SVD::SVD(const MMatrixXd &X, const MVectorXd &y) : lm(X, y) {
130130
SVDType UDV = X.jacobiSvd(Eigen::ComputeThinU|Eigen::ComputeThinV);
131131
VectorXd D = UDV.singularValues();
132-
m_r = std::count_if(D.data(), D.data() + m_p,
133-
std::bind2nd(std::greater<double>(), threshold() * D[0]));
132+
m_r = (D.array() > threshold() * D[0]).count();
134133
m_coef = UDV.solve(y);
135134
m_fitted = X * m_coef;
136135
MatrixXd VDi = UDV.matrixV() * DiagType(UDV.singularValues().array().inverse().matrix());

0 commit comments

Comments
 (0)