[Rcpp-devel] Map Eigen MatrixXf?

Yixuan Qiu yixuan.qiu at cos.name
Thu Jun 25 07:28:48 CEST 2015


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 <cdetermanjr at 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 at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>



-- 
Yixuan Qiu <yixuan.qiu at cos.name>
Department of Statistics,
Purdue University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150625/a37caf63/attachment.html>


More information about the Rcpp-devel mailing list