<div dir="ltr">Hi,<div><br></div><div>I'm interested in combining faster linear model estimation via QR decompositions from RcppEigen with JJs new(er) RcppParallel package to do cross validation and bootstrapping on linear models.</div><div><br></div><div>As a first step, I've been trying to merge the JSS paper on RcppEigen ( <a href="http://www.jstatsoft.org/v52/i05/paper">http://www.jstatsoft.org/v52/i05/paper</a> ) with about the documentation for RcppParallel ( <a href="http://rcppcore.github.io/RcppParallel/#examples">http://rcppcore.github.io/RcppParallel/#examples</a> )</div><div><br></div><div>ignoring bootstrapping and cross validation for the time being and just getting a linear model to run in the parallel framework.  I've toyed with each separately successfuly, and think I am somewhat close to getting them together, but I am running into an error:</div><div><br></div><div><div>partest.cpp:28:20: error: 'X' is not a type</div><div>partest.cpp:29:26: error: 'PQR' is not a type</div><div>partest.cpp:29:29: error: expected ',' or '...' before '.' token</div><div>partest.cpp:30:15: error: 'PQR' is not a type</div><div>partest.cpp:30:18: error: expected ',' or '...' before '.' token</div><div>partest.cpp: In member function 'virtual void CVLM::operator()(std::size_t, std::size_t)':</div><div>partest.cpp:44:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]</div><div>make: *** [partest.o] Error 1</div></div><div><br></div><div>My code is below (run via sourceCpp() ), and I can see exactly where the first error occurs, but I don't understand why this is OK when run outside of RcppParallel, but so very wrong in conjunction with RcppParallel.</div><div><br></div><div>Any pointers on either what's wrong or where I should be reading would be deeply appreciated.</div><div><br></div><div>Josh (code below)</div><div><br></div><div><br></div><div><div>// [[Rcpp::depends(RcppParallel)]]</div><div>// [[Rcpp::depends(RcppEigen)]]</div><div>#include <Rcpp.h></div><div>#include <RcppEigen.h></div><div>#include <RcppParallel.h></div><div><br></div><div>using namespace std;</div><div>using namespace Rcpp;</div><div>using namespace RcppParallel;</div><div><br></div><div>using Eigen::Lower;</div><div>using Eigen::Map;</div><div>using Eigen::MatrixXd;</div><div>using Eigen::Upper;</div><div>using Eigen::VectorXd;</div><div>typedef Map<MatrixXd> MapMatd;</div><div>typedef Map<VectorXd> MapVecd;</div><div>typedef Eigen::ColPivHouseholderQR<MatrixXd> CPivQR;</div><div>typedef CPivQR::PermutationType Permutation;</div><div><br></div><div>struct CVLM : public Worker</div><div>{</div><div>  // design matrix and outcome</div><div>  const Eigen::VectorXd y;</div><div>  const Eigen::MatrixXd X;</div><div><br></div><div>  // QR Decomposition</div><div>  const CPivQR PQR(X); // ERROR HAPPENS HERE</div><div>  const Permutation Pmat(PQR.colsPermutation());</div><div>  const int r(PQR.rank());</div><div><br></div><div><br></div><div>  // output</div><div>  RMatrix<double> betamat;</div><div>  Eigen::VectorXd betahat;</div><div><br></div><div>  // initialize with input and output</div><div>  CVLM(const Eigen::VectorXd y, const Eigen::MatrixXd X, Rcpp::NumericMatrix betamat)</div><div>    : y(y), X(X), betamat(betamat) {}</div><div><br></div><div>  void operator()(std::size_t begin, std::size_t end) {</div><div><br></div><div>    //betahat = PQR.solve(y);</div><div>    for(int j = begin; j < end; j++) {</div><div>      betamat(j, j) = X(j, j) + y[j];</div><div>    }</div><div>  }</div><div>};</div><div><br></div><div>// [[Rcpp::export]]</div><div>NumericMatrix parallelFit(Eigen::VectorXd dv, Eigen::MatrixXd x) {</div><div><br></div><div>  // allocate the output matrix</div><div>  NumericMatrix betamat(x.rows(), x.cols());</div><div><br></div><div>  // pass input and output</div><div>  CVLM cvLM(dv, x, betamat);</div><div><br></div><div>  // parallelFor to do it</div><div>  parallelFor(0, x.rows(), cvLM);</div><div><br></div><div>  return betamat;</div><div>}</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Joshua F. Wiley</div><div><a href="http://joshuawiley.com/" style="font-size:12.8000001907349px" target="_blank">http://joshuawiley.com/</a></div><div>---<br>Postdoctoral Research Fellow</div><div>Mary MacKillop Institute for Health Research</div><div>Australian Catholic University</div><div>---</div><div>Senior Analyst, Elkhart Group Ltd.<br><a href="http://elkhartgroup.com" target="_blank">http://elkhartgroup.com</a><br>Office: 260.673.5518</div></div></div>
</div></div>