![](/img/trans.png)
[英]Invert a Eigen::VectorXd and assign to another Eigen::VectorXd
[英]convert Rcpp::NumericVector to Eigen::VectorXd
之前有人问过类似的问题:
在Rcpp(Eigen)中的NumericVector / Matrix和VectorXd / MatrixXd之间转换以执行Cholesky解
问题是,我在fastLm.cpp中找到的代码(最后)对我不起作用。
Rcpp::NumericVector X( (SEXP) R.parseEval("x <- 1:10"));
Eigen::Map<Eigen::VectorXd> XS(Rcpp::as<Eigen::Map<Eigen::VectorXd>>(X)); //!!not working
它给出以下错误:
error: no matching constructor for initialization of 'Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >'
Exporter( SEXP x ) : t(x){}
和(除其他人之外):
note: candidate constructor (the implicit copy constructor) not viable: cannot convert argument of incomplete type 'SEXP' (aka 'SEXPREC *') to 'const Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >'
template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
它可能与SEXP对象有关?
如果在>>
之间再增加一个空格,它对我>>
:
R> cppFunction("bool conv(NumericVector X) { \
Eigen::Map<Eigen::VectorXd> \
XS(Rcpp::as<Eigen::Map<Eigen::VectorXd> >(X)); return true; } ",
depends="RcppEigen")
R> conv(1:4)
[1] TRUE
R>
而且,我不认为你可以说
X((SEXP) R.parseEval("x <- 1:10"))
除非您使用RInside,它有自己的Eigen示例-为此
cd examples/eigen
make
./rinside_sample0
./rinside_sample1
两者仍然可以在我的安装中正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.