[Rcpp-devel] How to increase the coding efficiency

Dirk Eddelbuettel edd at debian.org
Thu Dec 6 20:14:06 CET 2012


On 6 December 2012 at 12:33, Douglas Bates wrote:
| // [[Rcpp::depends(RcppEigen)]]
| #include <RcppEigen.h>
| 
| typedef Eigen::MatrixXd                 Mat;
| typedef Eigen::Map<Mat>                MMat;
| typedef Eigen::HouseholderQR<Mat>        QR;
| typedef Eigen::VectorXd                 Vec;
| typedef Eigen::Map<Vec>                MVec;
| 
| // [[Rcpp::export]]
| 
| Rcpp::List wtls(const MMat X, const MVec y, const MVec sqrtwts) {
|     return Rcpp::List::create(Rcpp::Named("betahat") =
| 			      QR(sqrtwts.asDiagonal()*X).solve(sqrtwts.asDiagonal()*y));
| }

That is a thing of beauty.  Nicely done, Doug!

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list