Hi Charles, The Map class is designed to reuse the memory allocated by some other program such as R, and due to this reason the memory layout must be consistent with the declared matrix type. In R there is no such float arrays, so there is no way to directly map it to a MatrixXf object. I suppose you can make a copy of the source matrix and cast it to float type using the cast() method.
Best, Yixuan 2015-06-25 3:31 GMT+08:00 Charles Determan <cdeterma...@gmail.com>: > I have been exploring the use of RcppEigen more recently and stumbled upon > an issue when passing R objects. Is there a way to pass an R matrix and > get it in to a mapped Eigen MatrixXf object? I know R doesn't have a > native float type so I am not overly surprised that I have run in to this > issue. > > For example, the following works simply when expecting a double matrix. > > #include <RcppEigen.h> > > // [[Rcpp::depends(RcppEigen)]] > > using Eigen::Map; > using Eigen::MatrixXd; > > // [[Rcpp::export]] > void floatMatrix(Map<MatrixXd> M){ > std::cout << M << std::endl; > } > > However, when I try to change MatrixXd to MatrixXf the compilation fails > stating: > > no matching function for call to 'eigen::Map<Eigen::Matrix<float, -1, > -1> ::Map(Rcpp::Vector<14, Rcpp::PreserveStorage>::iterator, int&, int&)' > > I tried searching around online if I could downcast the Mapped MatrixXd > but I have been unsuccessful. Any insights would be appreciated. > > Regards, > Charles > > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > -- Yixuan Qiu <yixuan....@cos.name> Department of Statistics, Purdue University
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel