[Rcpp-commits] r3114 - pkg/RcppEigen/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 30 20:21:53 CEST 2011


Author: dmbates
Date: 2011-06-30 20:21:53 +0200 (Thu, 30 Jun 2011)
New Revision: 3114

Modified:
   pkg/RcppEigen/src/fastLm.cpp
Log:
Code simplification suggested by Gael Guennebaud


Modified: pkg/RcppEigen/src/fastLm.cpp
===================================================================
--- pkg/RcppEigen/src/fastLm.cpp	2011-06-30 07:29:10 UTC (rev 3113)
+++ pkg/RcppEigen/src/fastLm.cpp	2011-06-30 18:21:53 UTC (rev 3114)
@@ -59,10 +59,10 @@
     PermutationType    Pmat = PQR.colsPermutation();
     m_perm                  = Pmat.indices();
     m_r                     = PQR.rank();
-    m_df                    = m_n - m_r;
     MatrixXd              R = PQR.matrixQR().topLeftCorner(m_p, m_p);
 
     if (m_r < (int)m_p) {		// The rank-deficient case
+	m_df                = m_n - m_r;
 	int           nsing = m_p - m_r;
 	MatrixXd     Atrunc = (X * Pmat).leftCols(m_r);
 	QRType           QR(Atrunc);
@@ -129,8 +129,7 @@
 SVD::SVD(const MMatrixXd &X, const MVectorXd &y) : lm(X, y) {
     SVDType  UDV = X.jacobiSvd(Eigen::ComputeThinU|Eigen::ComputeThinV);
     VectorXd   D = UDV.singularValues();
-    m_r          = std::count_if(D.data(), D.data() + m_p,
-				 std::bind2nd(std::greater<double>(), threshold() * D[0]));
+    m_r          = (D.array() > threshold() * D[0]).count();
     m_coef       = UDV.solve(y);
     m_fitted     = X * m_coef;
     MatrixXd VDi = UDV.matrixV() * DiagType(UDV.singularValues().array().inverse().matrix());



More information about the Rcpp-commits mailing list