3

有没有办法将一个转换arma::subview<double>成一个SEXP?在我的代码中创建矩阵后,我有以下X代码Rcpp

  //.... MCMC loop
  if(i % skiplength == 0) {
    for(unsigned int k=0; k < X.n_rows; k++) {
      X(k,index) = y[k];
    }
    index = index + 1;
  }
  // return matrix of samples in columns
  return Rcpp::wrap(X.submat( arma::span(0, X.n_rows - 1) , arma::span(discard, X.n_cols-1)));
END_RCPP
}

但我收到一条错误消息,指定:cannot convert 'const arma::subview<double>' to SEXP in initialization。有一个简单的解决方法吗?

一个可重现的例子

reproducible = '
arma::subview<double> conv(arma::Mat<double> m) {
return m.submat(arma::span(0, m.n_rows),arma::span(0, m.n_cols));
}'

cppFunction(code = reproducible, depends = "RcppArmadillo", verbose = TRUE)
4

1 回答 1

3

刚刚弄清楚了,子视图显然可以转换为矩阵

我换了

return Rcpp::wrap(X.submat( arma::span(0, X.n_rows - 1) , arma::span(discard, X.n_cols-1)));

arma::mat ret = X.submat(arma::span(0, X.n_rows - 1) , arma::span(discard, X.n_cols-1));
return Rcpp::wrap(ret);

它编译得很好。

于 2013-08-13T17:58:17.227 回答