<div dir="ltr">Hi Charles,<div>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.</div><div><br></div><div><br></div><div>Best,</div><div>Yixuan</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-25 3:31 GMT+08:00 Charles Determan <span dir="ltr"><<a href="mailto:cdetermanjr@gmail.com" target="_blank">cdetermanjr@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>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.<br><br></div>For example, the following works simply when expecting a double matrix.<br><br>#include <RcppEigen.h><br><br>// [[Rcpp::depends(RcppEigen)]]<br><br>using Eigen::Map;<br>using Eigen::MatrixXd;<br><br>// [[Rcpp::export]]<br>void floatMatrix(Map<MatrixXd> M){<br>    std::cout << M << std::endl;<br>}<br><br></div>However, when I try to change MatrixXd to MatrixXf the compilation fails stating:<br><br></div>    no matching function for call to 'eigen::Map<Eigen::Matrix<float, -1, -1> ::Map(Rcpp::Vector<14, Rcpp::PreserveStorage>::iterator, int&, int&)'<br><br></div>I tried searching around online if I could downcast the Mapped MatrixXd but I have been unsuccessful.  Any insights would be appreciated.<br><br></div>Regards,<br></div>Charles<br></div>
<br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Yixuan Qiu <<a href="mailto:yixuan.qiu@cos.name" target="_blank">yixuan.qiu@cos.name</a>><br>Department of Statistics,<br>Purdue University<br></div>
</div>