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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 23 20:03:32 CEST 2011


Author: dmbates
Date: 2011-06-23 20:03:32 +0200 (Thu, 23 Jun 2011)
New Revision: 3104

Modified:
   pkg/RcppEigen/src/fastLm.cpp
Log:
Don't try to extract names that aren't there.


Modified: pkg/RcppEigen/src/fastLm.cpp
===================================================================
--- pkg/RcppEigen/src/fastLm.cpp	2011-06-23 18:02:33 UTC (rev 3103)
+++ pkg/RcppEigen/src/fastLm.cpp	2011-06-23 18:03:32 UTC (rev 3104)
@@ -166,15 +166,18 @@
 	if ((Index)y.size() != n)
 	    throw std::invalid_argument("size mismatch");
 	const MVectorXd       yy(y.begin(), n);
-	lm                   ans = do_lm(MMatrixXd(X.begin(), n, p), yy, as<int>(type));
-	
+        const MMatrixXd       XX(X.begin(), n, p);
+
+	lm                   ans = do_lm(MMatrixXd(X.begin(), n, p), yy, ::Rf_asInteger(type));
 	NumericVector       coef(ans.coef().data(), ans.coef().data() + p);
 				// install the names, if available
 	List            dimnames = X.attr("dimnames");
-	RObject         colnames = dimnames[1];
-	if (!(colnames).isNULL())
-	    coef.attr("names") = clone(CharacterVector(colnames));
-
+	if (dimnames.size() > 1) {
+	    RObject         colnames = dimnames[1];
+	    if (!(colnames).isNULL())
+		coef.attr("names") = clone(CharacterVector(colnames));
+	}
+	    
 	VectorXd           resid = yy - ans.fitted();
 	double                s2 = resid.squaredNorm()/ans.df();
 	PermutationType     Pmat = PermutationType(p);
@@ -225,7 +228,7 @@
 	XtX                   = XtX.setZero().selfadjointView<Eigen::Lower>().rankUpdate(Xe.adjoint());
 	NumericMatrix     ans(p, p);
 	std::copy(XtX.data(), XtX.data() + XtX.size(), ans.begin());
-	return                  ans;
+	return                   ans;
     } catch( std::exception &ex ) {
 	forward_exception_to_r( ex );
     } catch(...) { 



More information about the Rcpp-commits mailing list