有没有办法将一个转换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)