<div dir="ltr"><div><div>Thanks Yixuan, I expected this was the case but thought it was worth asking.  It really seems a shame to me that R doesn't have float arrays.  In the mean time I guess I will need to have the functions create copies.<br><br><br></div>Regards,<br></div>Charles<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 25, 2015 at 12:28 AM, Yixuan Qiu <span dir="ltr"><<a href="mailto:yixuan.qiu@cos.name" target="_blank">yixuan.qiu@cos.name</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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"><div><div class="h5">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></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><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></div></div>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">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><span class="HOEnZb"><font color="#888888"><br></font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>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>
</font></span></div>
</blockquote></div><br></div>