将Rcpp::NumericVector转换为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
在我的安装中仍然可以正常运行。
相关文章:
- Eigen如何在容器循环中干净地附加矩阵
- 当在带有Eigen的C++中使用GDB时,我如何才能看到更多的大矩阵
- 如何在没有数据拷贝的情况下从指针创建一个Eigen VectorXd对象
- Eigen::VectorXd 和 Boost::Odeint,不起作用
- EIGEN地图类:将C阵列映射到VectorXD指针以有效的方式
- 内存效率-EIGEN :: vectorxd在循环中
- 从一个内存的一个块创建许多eigen :: vectorxd
- 将“Eigen::VectorXd”的集合合并为一个大的“Eigen::VectorXd”
- Un-flatten Eigen::VectorXd to Eigen::MatrixXd
- 两个Eigen::VectorXd的有效(非标准)连接
- 如何使用另一个"Eigen::VectorXd"向量中的值初始化"Eigen::VectorXd",基于索引的"向量<int>"
- 为什么 std::less<Eigen::VectorXd> 编译失败?
- c++ lambda 函数,用于将 Eigen::VectorXd 转换为 Eigen::MatrixXd
- 从eigen :: vectorxd获取矩阵视图/块而无需复制(共享内存)
- 指向eigen matrixxd的子行,表现得像vectorxd
- 如何从双指针数组创建 Eigen::VectorXd
- 将Eigen::VectorXd类型转换为std::vector
- 在访问Eigen::VectorXd时使用0作为第二个索引是否安全?
- 将Rcpp::NumericVector转换为Eigen::VectorXd
- 如何在Eigen中定义VectorXd数组